helperrepo

package
v0.0.0-...-10bc8b7 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMongoClient

func GetMongoClient() (*mongo.Client, error)

GetMongoClient : To Get Mongo Client Object

func IsDuplicateKey

func IsDuplicateKey(key string, err error) bool

IsDuplicateKey test if a key already exist on storage

func IsKeyDuplicated

func IsKeyDuplicated(err error) bool

IsKeyDuplicated test if a key already exist on storage

func IsNotFound

func IsNotFound(err error) bool

IsNotFound resource not found

Types

type Map

type Map map[string]interface{}

func MergeDefaultProjection

func MergeDefaultProjection(p Map) Map

MergeDefaultProjection merge projection with required values

type Repo

type Repo struct {
	Storage    Storage
	Collection *mongo.Collection
}

Repo all table DB instances

func (*Repo) Aggregate

func (db *Repo) Aggregate(
	ctx context.Context,
	results interface{},
	col string,
	pipeline interface{},
	options *options.AggregateOptions,
) error

func (*Repo) BulkWrite

func (db *Repo) BulkWrite(ctx context.Context, operations []mongo.WriteModel, op *options.BulkWriteOptions) error

func (*Repo) CountBy

func (db *Repo) CountBy(ctx context.Context, query Map) (int64, error)

func (*Repo) CountManyByOwner

func (db *Repo) CountManyByOwner(ctx context.Context, ownerID string, query Map) (int64, error)

func (*Repo) DeleteFile

func (db *Repo) DeleteFile(ctx context.Context, filename string) error

func (*Repo) DeleteMany

func (db *Repo) DeleteMany(ctx context.Context, query Map) error

func (*Repo) DeleteOne

func (db *Repo) DeleteOne(ctx context.Context, data helpermodels.Datable) error

func (*Repo) Find

func (db *Repo) Find(ctx context.Context, query Map, data interface{}, opts ...*options.FindOptions) error

func (*Repo) FindBy

func (db *Repo) FindBy(ctx context.Context, by, key string, p Map, result helpermodels.Datable) error

func (*Repo) FindByID

func (db *Repo) FindByID(ctx context.Context, id string, p Map, result helpermodels.Datable) error

func (*Repo) FindOne

func (db *Repo) FindOne(ctx context.Context, query Map, data interface{}, opts ...*options.FindOneOptions) error

func (*Repo) GetFile

func (db *Repo) GetFile(ctx context.Context, id string) ([]byte, int64, error)

func (*Repo) Insert

func (db *Repo) Insert(ctx context.Context, data helpermodels.Datable) error

func (*Repo) SaveFile

func (db *Repo) SaveFile(ctx context.Context, filename, fileType string, file []byte) error

func (*Repo) SoftDeleteMany

func (db *Repo) SoftDeleteMany(ctx context.Context, q Map) error

func (*Repo) UpdateMany

func (db *Repo) UpdateMany(ctx context.Context, query Map, updateWith Map, opts ...*options.UpdateOptions) error

func (*Repo) UpdateOne

func (db *Repo) UpdateOne(ctx context.Context, data helpermodels.Datable, upsert bool) error

type Repoable

type Repoable interface {
	DeleteFile(ctx context.Context, filename string) error
	SaveFile(ctx context.Context, filename, fileType string, file []byte) error
	GetFile(ctx context.Context, id string) ([]byte, int64, error)
	FindBy(ctx context.Context, by, key string, p Map, result helpermodels.Datable) error
	Find(ctx context.Context, query Map, data interface{}, opts ...*options.FindOptions) error
	FindOne(ctx context.Context, query Map, data interface{}, opts ...*options.FindOneOptions) error
	FindByID(ctx context.Context, id string, p Map, result helpermodels.Datable) error
	Insert(ctx context.Context, data helpermodels.Datable) error
	UpdateOne(ctx context.Context, data helpermodels.Datable, upsert bool) error
	UpdateMany(ctx context.Context, query Map, updateWith Map, opts ...*options.UpdateOptions) error
	CountManyByOwner(ctx context.Context, ownerID string, query Map) (int64, error)
	CountBy(ctx context.Context, query Map) (int64, error)
	BulkWrite(ctx context.Context, operations []mongo.WriteModel, op *options.BulkWriteOptions) error
	SoftDeleteMany(ctx context.Context, q Map) error
	DeleteOne(ctx context.Context, data helpermodels.Datable) error
	DeleteMany(ctx context.Context, query Map) error
	Aggregate(ctx context.Context, r interface{}, c string, p interface{}, o *options.AggregateOptions) error
}

type Storage

type Storage interface {
	GetDatabase() *mongo.Database
	GetCollection(name string) *mongo.Collection
}

func NewStorage

func NewStorage(prefix string) (Storage, error)

New create new Storage Struct

type StorageMongo

type StorageMongo struct {
	Database         string
	CollectionPrefix string
	// contains filtered or unexported fields
}

StorageMongo define all storage action and methods

func (*StorageMongo) GetCollection

func (s *StorageMongo) GetCollection(name string) *mongo.Collection

func (*StorageMongo) GetDatabase

func (s *StorageMongo) GetDatabase() *mongo.Database

Jump to

Keyboard shortcuts

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