databases

package
v0.0.0-...-c0ed8fc Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FindOne routineType = iota
	UpdateOne
	InsertOne
	DeleteOne
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DBClient

type DBClient interface {
	Connect() error
	Close() error
	GetBucket(bucketName string) (*gridfs.Bucket, error)
	GetCollection(collectionName string) DBCollection
	NewDBHandler(collectionName string) *DBRepo[DBRecord]
}

DBClient is an abstraction of the dbClient and testDBClient types

type DBCollection

type DBCollection interface {
	InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
	InsertMany(ctx context.Context, documents []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)
	DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
	FindOneAndDelete(ctx context.Context, filter interface{}, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult
	UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	UpdateByID(ctx context.Context, id interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (cur *mongo.Cursor, err error)
	FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult
	CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)
	DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
}

DBCollection is an abstraction of the dbClient and testDBClient types

type DBCursor

type DBCursor interface {
	Next(ctx context.Context) bool
	Decode(val interface{}) error
	Close(ctx context.Context) error
	Err() error
}

DBCursor is an abstraction of the dbClient and testDBClient types

type DBRecord

type DBRecord interface {
	ToDoc() (doc bson.D, err error)
	BsonFilter() (doc bson.D, err error)
	BsonUpdate() (doc bson.D, err error)
	BsonLoad(doc bson.D) (err error)
	AddTimeStamps(newRecord bool)
	AddObjectID()
	PostProcess() (err error)
	GetID() (id interface{})
	Update(doc interface{}) (err error)
	Match(doc interface{}) bool
}

DBRecord is an abstraction of the db model types

type DBRepo

type DBRepo[T DBRecord] struct {
	DB         DBClient
	Collection DBCollection
}

DBRepo is a Generic type struct for organizing dbModel methods

func (*DBRepo[T]) Count

func (h *DBRepo[T]) Count(filter T) (int64, error)

Count Function to update a dbModel from datasource with custom filter and update model

func (*DBRepo[T]) DeleteMany

func (h *DBRepo[T]) DeleteMany(filter T) (T, error)

DeleteMany adds a new dbModel record to a collection

func (*DBRepo[T]) DeleteOne

func (h *DBRepo[T]) DeleteOne(filter T) (T, error)

DeleteOne adds a new dbModel record to a collection

func (*DBRepo[T]) FindMany

func (h *DBRepo[T]) FindMany(filter T) ([]T, error)

FindMany is used to get a slice of dbModels from the db with custom filter

func (*DBRepo[T]) FindOne

func (h *DBRepo[T]) FindOne(filter T) (T, error)

FindOne is used to get a dbModel from the db with custom filter

func (*DBRepo[T]) FindOneAsync

func (h *DBRepo[T]) FindOneAsync(tCh chan T, eCh chan error, filter T, wg *sync.WaitGroup)

FindOneAsync is used to get a dbModel from the db with custom filter

func (*DBRepo[T]) InsertOne

func (h *DBRepo[T]) InsertOne(m T) (T, error)

InsertOne adds a new dbModel record to a collection

func (*DBRepo[T]) PaginatedFind

func (h *DBRepo[T]) PaginatedFind(ctx context.Context, filter T, pagination *utilities.Pagination) ([]T, error)

PaginatedFind is used to get a slice of dbModels from the db with custom filter

func (*DBRepo[T]) UpdateOne

func (h *DBRepo[T]) UpdateOne(filter T, m T) (T, error)

UpdateOne Function to update a dbModel from datasource with custom filter and update model

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳