wrapper

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeCursor

func DecodeCursor[T any](cursor *mongo.Cursor) ([]T, error)

func EvaluateAndDecodeSingleResult

func EvaluateAndDecodeSingleResult(result *mongo.SingleResult, v interface{}) error

Types

type Account

type Account struct {
	AccountId int      `json:"account_id" bson:"account_id"`
	Limit     int      `json:"limit" bson:"limit"`
	Products  []string `json:"products" bson:"products"`
}

type Client

type Client struct {
	*mongo.Client
}
var MongoClient *Client

func Connect

func Connect(clientOpt *options.ClientOptions) *Client

func (*Client) Disconnect

func (client *Client) Disconnect()

func (*Client) GetCollection

func (client *Client) GetCollection(databaseName, collection string) *mongo.Collection

func (*Client) GetDatabase

func (client *Client) GetDatabase(dbName string) *mongo.Database

func (*Client) Transaction

func (client *Client) Transaction(sessionOpt *options.SessionOptions, trxOpt *options.TransactionOptions, function func(sessCtx mongo.SessionContext) (interface{}, error)) error

type Collection

type Collection[T any] struct {
	*mongo.Collection
}

func NewCollection

func NewCollection[T any](mongoClient *Client, databaseName, collectionName string) *Collection[T]

func (*Collection[T]) Aggregate

func (col *Collection[T]) Aggregate(logger Logger, pipeline interface{}, opts ...*options.AggregateOptions) ([]T, error)

func (*Collection[T]) AggregateWithTrx

func (col *Collection[T]) AggregateWithTrx(logger Logger, pipeline interface{}, sessCtx *mongo.SessionContext, opts ...*options.AggregateOptions) ([]T, error)

func (*Collection[T]) BulkWrite

func (col *Collection[T]) BulkWrite(logger Logger, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error)

func (*Collection[T]) BulkWriteWithTrx

func (col *Collection[T]) BulkWriteWithTrx(logger Logger, models []mongo.WriteModel, sessCtx *mongo.SessionContext, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error)

func (*Collection[T]) CountDocuments

func (col *Collection[T]) CountDocuments(logger Logger, filter interface{}, opts ...*options.CountOptions) (int, error)

func (*Collection[T]) CountDocumentsWithTrx

func (col *Collection[T]) CountDocumentsWithTrx(logger Logger, filter interface{}, sessCtx *mongo.SessionContext, opts ...*options.CountOptions) (int, error)

func (*Collection[T]) DeleteMany

func (col *Collection[T]) DeleteMany(logger Logger, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*Collection[T]) DeleteManyWithTrx

func (col *Collection[T]) DeleteManyWithTrx(logger Logger, filter interface{}, sessCtx *mongo.SessionContext, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*Collection[T]) DeleteOne

func (col *Collection[T]) DeleteOne(logger Logger, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*Collection[T]) DeleteOneWithTrx

func (col *Collection[T]) DeleteOneWithTrx(logger Logger, filter interface{}, sessCtx *mongo.SessionContext, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*Collection[T]) EstimatedDocumentCount

func (col *Collection[T]) EstimatedDocumentCount(logger Logger, opts ...*options.EstimatedDocumentCountOptions) (int, error)

func (*Collection[T]) EstimatedDocumentCountWithTrx

func (col *Collection[T]) EstimatedDocumentCountWithTrx(logger Logger, sessCtx *mongo.SessionContext, opts ...*options.EstimatedDocumentCountOptions) (int, error)

func (*Collection[T]) FindAll

func (col *Collection[T]) FindAll(logger Logger, filter interface{}, opts ...*options.FindOptions) ([]T, error)

func (*Collection[T]) FindAllWithTrx

func (col *Collection[T]) FindAllWithTrx(logger Logger, filter interface{}, sessCtx *mongo.SessionContext, opts ...*options.FindOptions) ([]T, error)

func (*Collection[T]) FindOne

func (col *Collection[T]) FindOne(logger Logger, data, filter interface{}, opts ...*options.FindOneOptions) error

func (*Collection[T]) FindOneAndDelete

func (col *Collection[T]) FindOneAndDelete(logger Logger, data, filter interface{}, opts ...*options.FindOneAndDeleteOptions) error

func (*Collection[T]) FindOneAndDeleteWithTrx

func (col *Collection[T]) FindOneAndDeleteWithTrx(logger Logger, data, filter interface{}, sessCtx *mongo.SessionContext, opts ...*options.FindOneAndDeleteOptions) error

func (*Collection[T]) FindOneAndModify

func (col *Collection[T]) FindOneAndModify(logger Logger, data, filter interface{}, update interface{}, opts ...*options.FindOneAndUpdateOptions) error

func (*Collection[T]) FindOneAndModifyWithTrx

func (col *Collection[T]) FindOneAndModifyWithTrx(logger Logger, data, filter interface{}, update interface{}, sessCtx *mongo.SessionContext, opts ...*options.FindOneAndUpdateOptions) error

func (*Collection[T]) FindOneAndReplace

func (col *Collection[T]) FindOneAndReplace(logger Logger, data, filter interface{}, replacement interface{}, opts ...*options.FindOneAndReplaceOptions) error

func (*Collection[T]) FindOneAndReplaceWithTrx

func (col *Collection[T]) FindOneAndReplaceWithTrx(logger Logger, data, filter interface{}, replacement interface{}, sessCtx *mongo.SessionContext, opts ...*options.FindOneAndReplaceOptions) error

func (*Collection[T]) FindOneWithTrx

func (col *Collection[T]) FindOneWithTrx(logger Logger, data, filter interface{}, sessCtx *mongo.SessionContext, opts ...*options.FindOneOptions) error

func (*Collection[T]) InsertMany

func (col *Collection[T]) InsertMany(logger Logger, documents []interface{}, opts ...*options.InsertManyOptions) (interface{}, error)

func (*Collection[T]) InsertManyWithTrx

func (col *Collection[T]) InsertManyWithTrx(logger Logger, documents []interface{}, sessCtx *mongo.SessionContext, opts ...*options.InsertManyOptions) (interface{}, error)

func (*Collection[T]) InsertOne

func (col *Collection[T]) InsertOne(logger Logger, document interface{}, opts ...*options.InsertOneOptions) (interface{}, error)

func (*Collection[T]) InsertOneWithTrx

func (col *Collection[T]) InsertOneWithTrx(logger Logger, document interface{}, sessCtx *mongo.SessionContext, opts ...*options.InsertOneOptions) (interface{}, error)

func (*Collection[T]) ReplaceOne

func (col *Collection[T]) ReplaceOne(logger Logger, filter interface{}, document interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)

func (*Collection[T]) ReplaceOneWithTrx

func (col *Collection[T]) ReplaceOneWithTrx(logger Logger, filter interface{}, document interface{}, sessCtx *mongo.SessionContext, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)

func (*Collection[T]) UpdateMany

func (col *Collection[T]) UpdateMany(logger Logger, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func (*Collection[T]) UpdateManyWithTrx

func (col *Collection[T]) UpdateManyWithTrx(logger Logger, filter interface{}, update interface{}, sessCtx *mongo.SessionContext, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func (*Collection[T]) UpdateOne

func (col *Collection[T]) UpdateOne(logger Logger, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func (*Collection[T]) UpdateOneWithTrx

func (col *Collection[T]) UpdateOneWithTrx(logger Logger, filter interface{}, update interface{}, sessCtx *mongo.SessionContext, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

type Logger

type Logger interface {
	SlowQuery(msg string)
	GetTimeoutDuration() time.Duration // context cancel timeout setting
	// slow query time settings
	GetSlowQueryDurationOfOne() time.Duration
	GetSlowQueryDurationOfMany() time.Duration
	GetSlowQueryDurationOfBulk() time.Duration
	GetSlowQueryDurationOfAggregation() time.Duration
}

type MyLogger

type MyLogger struct {
	*logrus.Logger
}

func (*MyLogger) GetSlowQueryDurationOfAggregation

func (l *MyLogger) GetSlowQueryDurationOfAggregation() time.Duration

func (*MyLogger) GetSlowQueryDurationOfBulk

func (l *MyLogger) GetSlowQueryDurationOfBulk() time.Duration

func (*MyLogger) GetSlowQueryDurationOfMany

func (l *MyLogger) GetSlowQueryDurationOfMany() time.Duration

func (*MyLogger) GetSlowQueryDurationOfOne

func (l *MyLogger) GetSlowQueryDurationOfOne() time.Duration

func (*MyLogger) GetTimeoutDuration

func (l *MyLogger) GetTimeoutDuration() time.Duration

func (*MyLogger) SlowQuery

func (l *MyLogger) SlowQuery(msg string)

Jump to

Keyboard shortcuts

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