godm

package module
v0.0.0-...-35f460b Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: MIT Imports: 15 Imported by: 0

README

godm

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDbClientAlreadyInit = errors.New("db: client already initialized")

	ErrDbClientNotInit = errors.New("db: client not initialized")

	ErrDbStatusCheckFailed = errors.New("db: status check failed")

	ErrDbEnvVariables = errors.New("db: missing db env variables")
)

Functions

func BsonToModel

func BsonToModel(b bson.M, m Model) error

func BuildIndexes

func BuildIndexes(ctx context.Context) error

func Connect

func Connect(ctx context.Context) error

func Count

func Count(ctx context.Context, m Model, filter bson.M) (int64, error)

func DeleteMany

func DeleteMany(ctx context.Context, m Model, filter bson.M) (*mongo.DeleteResult, error)

func DeleteOne

func DeleteOne(ctx context.Context, m Model, filter bson.M) error

func Disconnect

func Disconnect(ctx context.Context) error

func ExtendBson

func ExtendBson(dst bson.M, src bson.M)

func Find

func Find(ctx context.Context, m Model, filter bson.M, opts ...*options.FindOptions) (*mongo.Cursor, error)

func FindByID

func FindByID(ctx context.Context, m Model, mid interface{}) error

func FindOne

func FindOne(ctx context.Context, m Model, filter bson.M) error

func Init

func Init(usr, pwd string) error

func InsertOne

func InsertOne(ctx context.Context, m Model) error

func ModelToBson

func ModelToBson(m Model) (bson.M, error)

func RegisterModelFactoryFunc

func RegisterModelFactoryFunc(modelFunc modelFactoryFunc)

func RunInTransaction

func RunInTransaction(ctx context.Context, runOps func(mongo.SessionContext, func() error) error) error

func UpdateMany

func UpdateMany(ctx context.Context, m Model, filter bson.M, updates Updates, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func UpdateOne

func UpdateOne(ctx context.Context, m Model, updates Updates, opts ...*options.UpdateOptions) error

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

type Index

type Index struct {
	Fields  bson.M    `yaml:"fields"`
	Options IndexOpts `yaml:"options"`
}

type IndexOpts

type IndexOpts struct {
	Unique bool `yaml:"unique"`
	Sparse bool `yaml:"sparse"`
}

type Model

type Model interface {
	Collection() string
}

type PolymorphicModel

type PolymorphicModel interface {
	GetID() primitive.ObjectID
	Collection() string
}

type QueryIter

type QueryIter struct {
	// contains filtered or unexported fields
}

func FindIter

func FindIter(ctx context.Context, m Model, filter bson.M, opts ...*options.FindOptions) (*QueryIter, error)

func (*QueryIter) Close

func (iter *QueryIter) Close(ctx context.Context) error

func (*QueryIter) Collection

func (iter *QueryIter) Collection() string

func (*QueryIter) Err

func (iter *QueryIter) Err() error

func (*QueryIter) Iter

func (iter *QueryIter) Iter(ctx context.Context) <-chan Model

type Updates

type Updates bson.M

func ModelToUpdates

func ModelToUpdates(m Model) (Updates, error)

Jump to

Keyboard shortcuts

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