db

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTransaction

func WithTransaction(callback func(sessCtx mongo.SessionContext) (interface{}, error), opts ...*options.TransactionOptions) (interface{}, error)

Types

type DatabaseBase

type DatabaseBase interface {
	Init(config interface{}) error
	Connect()
	Close()
	GetClient() interface{}
	GetCollection(collection string) interface{}
	GetCursor(ctx context.Context, collection string,
		filter, sort interface{}, skip, limit int64,
		projection interface{}) (interface{}, error)

	Find(ctx context.Context, collection string,
		filter interface{}, option FindOption,
		projection, docs interface{}) error

	Distinct(ctx context.Context, collection, fieldName string,
		filter interface{}) ([]string, error)

	Aggregate(ctx context.Context, collection string, pipeline interface{},
		docs interface{}) error

	FindOne(ctx context.Context, collection string, filter interface{},
		projection interface{}, doc interface{}) error

	AggregateOne(ctx context.Context, collection string, pipeline interface{},
		doc interface{}) error

	// Insert executes an insert command to insert a single document into the collection.
	// The _id can be retrieved from the result.
	Insert(ctx context.Context, collection string, doc interface{}) (InsertOneResult, error)
	InsertMany(ctx context.Context, collection string, docs []interface{}) ([]interface{}, error)
	UpdateOne(ctx context.Context, collection string, filter, doc interface{}) (UpdateOneResult, error)
	FindOneAndUpdate(ctx context.Context, collection string, filter, update, doc interface{}) error
	UpdateMany(ctx context.Context, collection string, filter interface{},
		doc interface{}) (interface{}, error)

	DeleteOne(ctx context.Context, collection string, filter interface{}) (interface{}, error)
	DeleteMany(ctx context.Context, collection string, filter interface{}) (interface{}, error)
	Count(ctx context.Context, collection string, filter interface{}) (int64, error)

	EnsureIndex(ctx context.Context, collection string, name string, keys bson.M,
		unique bool) string
}

type FindOption

type FindOption struct {
	Sort  string
	Order string

	Skip  int64
	Limit int64
}

type InsertOneResult

type InsertOneResult struct {
	Id interface{} `json:"id"`
}

type MongoDBConfig

type MongoDBConfig struct {
	Host       string `yaml:"host"`
	Username   string `yaml:"user"`
	Password   string `yaml:"password"`
	AuthSource string `yaml:"authSource"`
	Name       string `yaml:"name"`
	ReplicaSet string `yaml:"replicaSet"`
}

YAML config for MongoDB

func (*MongoDBConfig) IsValid

func (c *MongoDBConfig) IsValid() bool

type MongoDb

type MongoDb struct {
	DatabaseBase
	// contains filtered or unexported fields
}

func GetMongoDb

func GetMongoDb() *MongoDb

func (*MongoDb) Aggregate

func (db *MongoDb) Aggregate(ctx context.Context, collection string, pipeline interface{},
	docs interface{}) error

func (*MongoDb) AggregateOne

func (db *MongoDb) AggregateOne(ctx context.Context, collection string, pipeline interface{},
	doc interface{}) error

func (*MongoDb) Close

func (db *MongoDb) Close()

func (*MongoDb) Connect

func (db *MongoDb) Connect()

func (*MongoDb) Count

func (db *MongoDb) Count(ctx context.Context, collection string, filter interface{}) (int64, error)

func (*MongoDb) DeleteMany

func (db *MongoDb) DeleteMany(ctx context.Context, collection string, filter interface{}) (interface{}, error)

func (*MongoDb) DeleteOne

func (db *MongoDb) DeleteOne(ctx context.Context, collection string, filter interface{}) (interface{}, error)

func (*MongoDb) Distinct

func (db *MongoDb) Distinct(ctx context.Context, collection, fieldName string,
	filter interface{}) ([]string, error)

func (*MongoDb) EnsureIndex

func (db *MongoDb) EnsureIndex(ctx context.Context, collection string, name string, keys bson.M,
	unique bool) string

func (*MongoDb) Find

func (db *MongoDb) Find(ctx context.Context, collection string,
	filter interface{}, option FindOption,
	projection, docs interface{}) error

func (*MongoDb) FindOne

func (db *MongoDb) FindOne(ctx context.Context, collection string, filter interface{},
	projection interface{}, doc interface{}) error

func (*MongoDb) FindOneAndUpdate

func (db *MongoDb) FindOneAndUpdate(ctx context.Context, collection string, filter interface{},
	update, doc interface{}) error

func (*MongoDb) GetClient

func (db *MongoDb) GetClient() interface{}

Returns the current session, *mongo.Client

func (*MongoDb) GetCollection added in v0.2.10

func (db *MongoDb) GetCollection(collection string) interface{}

func (*MongoDb) GetCursor

func (db *MongoDb) GetCursor(ctx context.Context, collection string,
	filter, sort interface{},
	skip, limit int64,
	projection interface{}) (interface{}, error)

func (*MongoDb) Init

func (db *MongoDb) Init(i interface{}) error

func (*MongoDb) Insert

func (db *MongoDb) Insert(ctx context.Context, collection string, doc interface{}) (InsertOneResult, error)

func (*MongoDb) InsertMany

func (db *MongoDb) InsertMany(ctx context.Context, collection string, docs []interface{}) ([]interface{}, error)

func (*MongoDb) UpdateMany

func (db *MongoDb) UpdateMany(ctx context.Context, collection string, filter interface{},
	update interface{}) (interface{}, error)

func (*MongoDb) UpdateOne

func (db *MongoDb) UpdateOne(ctx context.Context, collection string, filter interface{},
	update interface{}) (UpdateOneResult, error)

type Order

type Order string

type UpdateOneResult

type UpdateOneResult struct {
	Id interface{} `json:"id"`
}

Jump to

Keyboard shortcuts

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