utilMongodb

package
v0.0.0-...-5f3621a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: MulanPSL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(m ModelMongodb, results interface{}, group bson.D, filter interface{}, sort interface{}) (err error)

func CreateIndexes

func CreateIndexes(m ModelMongodb) (err error)

func Delete

func Delete(m ModelMongodb) (err error)

func Find

func Find(m ModelMongodb, filter interface{}, sort interface{}) (err error)

func InsertMany

func InsertMany(data []interface{}) (err error)

func MongodbHasIndexes

func MongodbHasIndexes(indexView mongo.IndexView) (found bool)

func Read

func Read(m ModelMongodb) (err error)

func Save

func Save(m ModelMongodb) (err error)

func Select

func Select(m ModelMongodb, results interface{}, filter interface{}, sort interface{}, limit int64, offset int64, total *int64) (err error)

func SetDefaultConfig

func SetDefaultConfig(host string, dbName string, user string, password string, loggerOptions ...*options.LoggerOptions) error

Types

type ModelBaseMongodb

type ModelBaseMongodb struct {
	Id        string `json:"id,omitempty" bson:"_id"`
	CreatedAt string `json:"created_at" bson:"created_at"`
	UpdatedAt string `json:"updated_at" bson:"updated_at"`
	// contains filtered or unexported fields
}

func (*ModelBaseMongodb) GetClient

func (m *ModelBaseMongodb) GetClient() (mc *MongodbClient)

func (*ModelBaseMongodb) GetId

func (m *ModelBaseMongodb) GetId() string

func (*ModelBaseMongodb) Indexes

func (m *ModelBaseMongodb) Indexes() (indexes []mongo.IndexModel)
func (m *ModelBaseMongodb) CollectionName() string {
	return ""
}

func (*ModelBaseMongodb) SetClient

func (m *ModelBaseMongodb) SetClient(mc *MongodbClient)

func (*ModelBaseMongodb) SetCreatedAt

func (m *ModelBaseMongodb) SetCreatedAt(t time.Time)

func (*ModelBaseMongodb) SetId

func (m *ModelBaseMongodb) SetId(id string)

func (*ModelBaseMongodb) SetUpdatedAt

func (m *ModelBaseMongodb) SetUpdatedAt(t time.Time)

type ModelMongodb

type ModelMongodb interface {
	SetId(id string)
	GetId() string
	CollectionName() string
	Indexes() (indexes []mongo.IndexModel)
	SetClient(mc *MongodbClient)
	GetClient() (mc *MongodbClient)

	SetCreatedAt(t time.Time)
	SetUpdatedAt(t time.Time)
}

type MongodbClient

type MongodbClient struct {
	Host          string
	DbName        string
	User          string
	Password      string
	LoggerOptions *options.LoggerOptions
	// contains filtered or unexported fields
}

func GetDefaultClient

func GetDefaultClient() *MongodbClient

func NewMongodbClient

func NewMongodbClient(host string, dbName string, user string, password string, loggerOptions ...*options.LoggerOptions) *MongodbClient

func (*MongodbClient) Aggregate

func (mc *MongodbClient) Aggregate(collection string, group bson.D, filter interface{}, sort interface{}, results interface{}) error

func (*MongodbClient) Collection

func (mc *MongodbClient) Collection(collection string) (*mongo.Collection, error)

func (*MongodbClient) Connect

func (mc *MongodbClient) Connect() error

func (*MongodbClient) CreateIndexes

func (mc *MongodbClient) CreateIndexes(collectionName string, indexModels []mongo.IndexModel) error

func (*MongodbClient) Delete

func (mc *MongodbClient) Delete(collection string, filter interface{}, count *int64) (err error)

func (*MongodbClient) Find

func (mc *MongodbClient) Find(collection string, filter interface{}, sort interface{}, result interface{}) (err error)

func (*MongodbClient) InsertMany

func (mc *MongodbClient) InsertMany(collectionName string, data []interface{}) (ids []string, err error)

func (*MongodbClient) InsertOne

func (mc *MongodbClient) InsertOne(collectionName string, data interface{}) (id string, err error)

func (*MongodbClient) Ping

func (mc *MongodbClient) Ping() error

func (*MongodbClient) Select

func (mc *MongodbClient) Select(collection string, filter interface{}, sort interface{}, limit int64, offset int64, results interface{}, total *int64) (err error)

func (*MongodbClient) Update

func (mc *MongodbClient) Update(collectionName string, filter interface{}, update interface{}) (count int64, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL