Documentation
¶
Index ¶
- Constants
- type DBClient
- type DBCollection
- type DBCursor
- type DBRecord
- type DBRepo
- func (h *DBRepo[T]) Count(filter T) (int64, error)
- func (h *DBRepo[T]) DeleteMany(filter T) (T, error)
- func (h *DBRepo[T]) DeleteOne(filter T) (T, error)
- func (h *DBRepo[T]) FindMany(filter T) ([]T, error)
- func (h *DBRepo[T]) FindOne(filter T) (T, error)
- func (h *DBRepo[T]) FindOneAsync(tCh chan T, eCh chan error, filter T, wg *sync.WaitGroup)
- func (h *DBRepo[T]) InsertOne(m T) (T, error)
- func (h *DBRepo[T]) PaginatedFind(ctx context.Context, filter T, pagination *utilities.Pagination) ([]T, error)
- func (h *DBRepo[T]) UpdateOne(filter T, m T) (T, error)
Constants ¶
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 ¶
Count Function to update a dbModel from datasource with custom filter and update model
func (*DBRepo[T]) DeleteMany ¶
DeleteMany adds a new dbModel record to a collection
func (*DBRepo[T]) FindMany ¶
FindMany is used to get a slice of dbModels from the db with custom filter
func (*DBRepo[T]) FindOneAsync ¶
FindOneAsync is used to get a dbModel from the db with custom filter
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