280 lines
9.0 KiB
Go
280 lines
9.0 KiB
Go
// --------------------------------------------------------------------------------------------
|
|
// The following code is automatically generated by the mongo-dao-generator tool.
|
|
// Please do not modify this code manually to avoid being overwritten in the next generation.
|
|
// For more tool details, please click the link to view https://github.com/dobyte/mongo-dao-generator
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
package internal
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
modelpkg "mongo.games.com/game/model"
|
|
)
|
|
|
|
type AccountLogFilterFunc func(cols *AccountLogColumns) interface{}
|
|
type AccountLogUpdateFunc func(cols *AccountLogColumns) interface{}
|
|
type AccountLogPipelineFunc func(cols *AccountLogColumns) interface{}
|
|
type AccountLogCountOptionsFunc func(cols *AccountLogColumns) *options.CountOptions
|
|
type AccountLogAggregateOptionsFunc func(cols *AccountLogColumns) *options.AggregateOptions
|
|
type AccountLogFindOneOptionsFunc func(cols *AccountLogColumns) *options.FindOneOptions
|
|
type AccountLogFindManyOptionsFunc func(cols *AccountLogColumns) *options.FindOptions
|
|
type AccountLogUpdateOptionsFunc func(cols *AccountLogColumns) *options.UpdateOptions
|
|
type AccountLogDeleteOptionsFunc func(cols *AccountLogColumns) *options.DeleteOptions
|
|
type AccountLogInsertOneOptionsFunc func(cols *AccountLogColumns) *options.InsertOneOptions
|
|
type AccountLogInsertManyOptionsFunc func(cols *AccountLogColumns) *options.InsertManyOptions
|
|
|
|
type AccountLog struct {
|
|
Columns *AccountLogColumns
|
|
Database *mongo.Database
|
|
Collection *mongo.Collection
|
|
}
|
|
|
|
type AccountLogColumns struct {
|
|
ID string
|
|
Platform string
|
|
SnId string
|
|
AccountType string
|
|
FaceBookId string
|
|
}
|
|
|
|
var accountLogColumns = &AccountLogColumns{
|
|
ID: "_id",
|
|
Platform: "platform",
|
|
SnId: "snid",
|
|
AccountType: "accounttype",
|
|
FaceBookId: "facebookid",
|
|
}
|
|
|
|
func NewAccountLog() *AccountLog {
|
|
return &AccountLog{
|
|
Columns: accountLogColumns,
|
|
}
|
|
}
|
|
|
|
// Count returns the number of documents in the collection.
|
|
func (dao *AccountLog) Count(ctx context.Context, filterFunc AccountLogFilterFunc, optionsFunc ...AccountLogCountOptionsFunc) (int64, error) {
|
|
var (
|
|
opts *options.CountOptions
|
|
filter = filterFunc(dao.Columns)
|
|
)
|
|
|
|
if len(optionsFunc) > 0 {
|
|
opts = optionsFunc[0](dao.Columns)
|
|
}
|
|
|
|
return dao.Collection.CountDocuments(ctx, filter, opts)
|
|
}
|
|
|
|
// Aggregate executes an aggregate command against the collection and returns a cursor over the resulting documents.
|
|
func (dao *AccountLog) Aggregate(ctx context.Context, pipelineFunc AccountLogPipelineFunc, optionsFunc ...AccountLogAggregateOptionsFunc) (*mongo.Cursor, error) {
|
|
var (
|
|
opts *options.AggregateOptions
|
|
pipeline = pipelineFunc(dao.Columns)
|
|
)
|
|
|
|
if len(optionsFunc) > 0 {
|
|
opts = optionsFunc[0](dao.Columns)
|
|
}
|
|
|
|
return dao.Collection.Aggregate(ctx, pipeline, opts)
|
|
}
|
|
|
|
// InsertOne executes an insert command to insert a single document into the collection.
|
|
func (dao *AccountLog) InsertOne(ctx context.Context, model *modelpkg.AccountLog, optionsFunc ...AccountLogInsertOneOptionsFunc) (*mongo.InsertOneResult, error) {
|
|
if model == nil {
|
|
return nil, errors.New("model is nil")
|
|
}
|
|
|
|
if err := dao.autofill(ctx, model); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var opts *options.InsertOneOptions
|
|
|
|
if len(optionsFunc) > 0 {
|
|
opts = optionsFunc[0](dao.Columns)
|
|
}
|
|
|
|
return dao.Collection.InsertOne(ctx, model, opts)
|
|
}
|
|
|
|
// InsertMany executes an insert command to insert multiple documents into the collection.
|
|
func (dao *AccountLog) InsertMany(ctx context.Context, models []*modelpkg.AccountLog, optionsFunc ...AccountLogInsertManyOptionsFunc) (*mongo.InsertManyResult, error) {
|
|
if len(models) == 0 {
|
|
return nil, errors.New("models is empty")
|
|
}
|
|
|
|
documents := make([]interface{}, 0, len(models))
|
|
for i := range models {
|
|
model := models[i]
|
|
if err := dao.autofill(ctx, model); err != nil {
|
|
return nil, err
|
|
}
|
|
documents = append(documents, model)
|
|
}
|
|
|
|
var opts *options.InsertManyOptions
|
|
|
|
if len(optionsFunc) > 0 {
|
|
opts = optionsFunc[0](dao.Columns)
|
|
}
|
|
|
|
return dao.Collection.InsertMany(ctx, documents, opts)
|
|
}
|
|
|
|
// UpdateOne executes an update command to update at most one document in the collection.
|
|
func (dao *AccountLog) UpdateOne(ctx context.Context, filterFunc AccountLogFilterFunc, updateFunc AccountLogUpdateFunc, optionsFunc ...AccountLogUpdateOptionsFunc) (*mongo.UpdateResult, error) {
|
|
var (
|
|
opts *options.UpdateOptions
|
|
filter = filterFunc(dao.Columns)
|
|
update = updateFunc(dao.Columns)
|
|
)
|
|
|
|
if len(optionsFunc) > 0 {
|
|
opts = optionsFunc[0](dao.Columns)
|
|
}
|
|
|
|
return dao.Collection.UpdateOne(ctx, filter, update, opts)
|
|
}
|
|
|
|
// UpdateOneByID executes an update command to update at most one document in the collection.
|
|
func (dao *AccountLog) UpdateOneByID(ctx context.Context, id string, updateFunc AccountLogUpdateFunc, optionsFunc ...AccountLogUpdateOptionsFunc) (*mongo.UpdateResult, error) {
|
|
objectID, err := primitive.ObjectIDFromHex(id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return dao.UpdateOne(ctx, func(cols *AccountLogColumns) interface{} {
|
|
return bson.M{"_id": objectID}
|
|
}, updateFunc, optionsFunc...)
|
|
}
|
|
|
|
// UpdateMany executes an update command to update documents in the collection.
|
|
func (dao *AccountLog) UpdateMany(ctx context.Context, filterFunc AccountLogFilterFunc, updateFunc AccountLogUpdateFunc, optionsFunc ...AccountLogUpdateOptionsFunc) (*mongo.UpdateResult, error) {
|
|
var (
|
|
opts *options.UpdateOptions
|
|
filter = filterFunc(dao.Columns)
|
|
update = updateFunc(dao.Columns)
|
|
)
|
|
|
|
if len(optionsFunc) > 0 {
|
|
opts = optionsFunc[0](dao.Columns)
|
|
}
|
|
|
|
return dao.Collection.UpdateMany(ctx, filter, update, opts)
|
|
}
|
|
|
|
// FindOne executes a find command and returns a model for one document in the collection.
|
|
func (dao *AccountLog) FindOne(ctx context.Context, filterFunc AccountLogFilterFunc, optionsFunc ...AccountLogFindOneOptionsFunc) (*modelpkg.AccountLog, error) {
|
|
var (
|
|
opts *options.FindOneOptions
|
|
model = &modelpkg.AccountLog{}
|
|
filter = filterFunc(dao.Columns)
|
|
)
|
|
|
|
if len(optionsFunc) > 0 {
|
|
opts = optionsFunc[0](dao.Columns)
|
|
}
|
|
|
|
err := dao.Collection.FindOne(ctx, filter, opts).Decode(model)
|
|
if err != nil {
|
|
if err == mongo.ErrNoDocuments {
|
|
return nil, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
return model, nil
|
|
}
|
|
|
|
// FindOneByID executes a find command and returns a model for one document in the collection.
|
|
func (dao *AccountLog) FindOneByID(ctx context.Context, id string, optionsFunc ...AccountLogFindOneOptionsFunc) (*modelpkg.AccountLog, error) {
|
|
objectID, err := primitive.ObjectIDFromHex(id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return dao.FindOne(ctx, func(cols *AccountLogColumns) interface{} {
|
|
return bson.M{"_id": objectID}
|
|
}, optionsFunc...)
|
|
}
|
|
|
|
// FindMany executes a find command and returns many models the matching documents in the collection.
|
|
func (dao *AccountLog) FindMany(ctx context.Context, filterFunc AccountLogFilterFunc, optionsFunc ...AccountLogFindManyOptionsFunc) ([]*modelpkg.AccountLog, error) {
|
|
var (
|
|
opts *options.FindOptions
|
|
filter = filterFunc(dao.Columns)
|
|
)
|
|
|
|
if len(optionsFunc) > 0 {
|
|
opts = optionsFunc[0](dao.Columns)
|
|
}
|
|
|
|
cur, err := dao.Collection.Find(ctx, filter, opts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
models := make([]*modelpkg.AccountLog, 0)
|
|
|
|
if err = cur.All(ctx, &models); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return models, nil
|
|
}
|
|
|
|
// DeleteOne executes a delete command to delete at most one document from the collection.
|
|
func (dao *AccountLog) DeleteOne(ctx context.Context, filterFunc AccountLogFilterFunc, optionsFunc ...AccountLogDeleteOptionsFunc) (*mongo.DeleteResult, error) {
|
|
var (
|
|
opts *options.DeleteOptions
|
|
filter = filterFunc(dao.Columns)
|
|
)
|
|
|
|
if len(optionsFunc) > 0 {
|
|
opts = optionsFunc[0](dao.Columns)
|
|
}
|
|
|
|
return dao.Collection.DeleteOne(ctx, filter, opts)
|
|
}
|
|
|
|
// DeleteOneByID executes a delete command to delete at most one document from the collection.
|
|
func (dao *AccountLog) DeleteOneByID(ctx context.Context, id string, optionsFunc ...AccountLogDeleteOptionsFunc) (*mongo.DeleteResult, error) {
|
|
objectID, err := primitive.ObjectIDFromHex(id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return dao.DeleteOne(ctx, func(cols *AccountLogColumns) interface{} {
|
|
return bson.M{"_id": objectID}
|
|
}, optionsFunc...)
|
|
}
|
|
|
|
// DeleteMany executes a delete command to delete documents from the collection.
|
|
func (dao *AccountLog) DeleteMany(ctx context.Context, filterFunc AccountLogFilterFunc, optionsFunc ...AccountLogDeleteOptionsFunc) (*mongo.DeleteResult, error) {
|
|
var (
|
|
opts *options.DeleteOptions
|
|
filter = filterFunc(dao.Columns)
|
|
)
|
|
|
|
if len(optionsFunc) > 0 {
|
|
opts = optionsFunc[0](dao.Columns)
|
|
}
|
|
|
|
return dao.Collection.DeleteMany(ctx, filter, opts)
|
|
}
|
|
|
|
// autofill when inserting data
|
|
func (dao *AccountLog) autofill(ctx context.Context, model *modelpkg.AccountLog) error {
|
|
if model.ID.IsZero() {
|
|
model.ID = primitive.NewObjectID()
|
|
}
|
|
|
|
return nil
|
|
}
|