68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
"mongo.games.com/goserver/core/logger"
|
|
"mongo.games.com/goserver/core/mongox"
|
|
|
|
"mongo.games.com/game/dao/internal"
|
|
modelpkg "mongo.games.com/game/model"
|
|
)
|
|
|
|
var (
|
|
_ = context.Background()
|
|
_ = logger.Logger
|
|
_ = bson.M{}
|
|
_ = mongo.Database{}
|
|
)
|
|
|
|
type PushCoinPoolColumns = internal.PushCoinPoolColumns
|
|
|
|
type PushCoinPool struct {
|
|
*internal.PushCoinPool
|
|
}
|
|
|
|
func GetPushCoinPool(key string) (*PushCoinPool, error) {
|
|
return mongox.GetDao(key, NewPushCoinPool)
|
|
}
|
|
|
|
func NewPushCoinPool(db *mongo.Database, c *mongo.Collection) (*PushCoinPool, any) {
|
|
if db == nil || c == nil {
|
|
return &PushCoinPool{}, &modelpkg.PushCoinPool{}
|
|
}
|
|
|
|
v := internal.NewPushCoinPool()
|
|
v.Database = db
|
|
v.Collection = c
|
|
|
|
return &PushCoinPool{PushCoinPool: v}, &modelpkg.PushCoinPool{}
|
|
}
|
|
|
|
func (p *PushCoinPool) Load() (*modelpkg.PushCoinPool, error) {
|
|
ret, err := p.FindOne(context.Background(), func(cols *internal.PushCoinPoolColumns) interface{} {
|
|
return bson.M{}
|
|
})
|
|
if err != nil {
|
|
logger.Logger.Errorf("PushCoinPool FindOne error: %v", err)
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (p *PushCoinPool) Save(data *modelpkg.PushCoinPool) error {
|
|
_, err := p.UpdateOneByID(context.Background(), data.ID.Hex(), func(cols *internal.PushCoinPoolColumns) interface{} {
|
|
return bson.M{"$set": data}
|
|
}, func(cols *internal.PushCoinPoolColumns) *options.UpdateOptions {
|
|
return options.Update().SetUpsert(true)
|
|
})
|
|
if err != nil {
|
|
logger.Logger.Error("PushCoinPool.Save ", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|