mongo

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewObjectID

func NewObjectID(id string) (primitive.ObjectID, error)

Types

type Database

type Database interface {
	GetInstance() *database
	Connect()
	Disconnect()
}

func NewDatabase

func NewDatabase(ctx context.Context, config DbConfig) Database

type DbConfig

type DbConfig struct {
	User        string
	Pwd         string
	Host        string
	Port        uint16
	Name        string
	MinPoolSize uint16
	MaxPoolSize uint16
	Timeout     time.Duration
}

type Document

type Document[T any] interface {
	EnsureIndexes(Database)
	GetValue() *T
	Validate() error
}

type Query

type Query[T any] interface {
	Close()
	CreateIndexes(indexes []mongo.IndexModel) error
	FindOne(filter bson.M, opts *options.FindOneOptions) (*T, error)
	FindAll(filter bson.M, opts *options.FindOptions) ([]*T, error)
	FindPaginated(filter bson.M, page int64, limit int64, opts *options.FindOptions) ([]*T, error)
	InsertOne(doc *T) (*primitive.ObjectID, error)
	InsertAndRetrieveOne(doc *T) (*T, error)
	InsertMany(doc []*T) ([]primitive.ObjectID, error)
	InsertAndRetrieveMany(doc []*T) ([]*T, error)
	UpdateOne(filter bson.M, update bson.M) (*mongo.UpdateResult, error)
	UpdateMany(filter bson.M, update bson.M) (*mongo.UpdateResult, error)
	DeleteOne(filter bson.M) (*mongo.DeleteResult, error)
}

type QueryBuilder

type QueryBuilder[T any] interface {
	GetCollection() *mongo.Collection
	SingleQuery() Query[T]
	Query(context context.Context) Query[T]
}

func NewQueryBuilder

func NewQueryBuilder[T any](db Database, collectionName string) QueryBuilder[T]

Jump to

Keyboard shortcuts

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