dbexts

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: BSD-3-Clause Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	SET  = "$set"
	BSON = "bson"
	OID  = "_id"
)

Variables

View Source
var (
	RegexEnvFile  *regexp.Regexp
	RegexDatabase *regexp.Regexp
)
View Source
var HexRegex *regexp.Regexp

Functions

func CollFactory

func CollFactory(collectionName string) func() *mongo.Collection

func ExtractValue

func ExtractValue(v reflect.Value) interface{}

func GetClient

func GetClient() *mongo.Client

func GetDatabase

func GetDatabase() *mongo.Database

func GetUpdate

func GetUpdate(ty reflect.Type, fieldName string, v1 reflect.Value, v2 reflect.Value) *bson.E

func Initialize

func Initialize(cfgPath string, pDatabaseName string)

func MakeUpdateStatements

func MakeUpdateStatements[A any](o A, n A) bson.D

func MkUpdateSetStatement

func MkUpdateSetStatement[A any](o A, n A) bson.D

func Shutdown

func Shutdown()

func ToOID

func ToOID(id string) *primitive.ObjectID

Types

type Entity

type Entity struct {
}

type Initializable

type Initializable[A any] interface {
	Init() Initializable[A]
}

type MongoCRUD

type MongoCRUD[A any] interface {
	Create(A) (*mongo.InsertOneResult, error)
	RetrieveById(oid primitive.ObjectID) *A
	RetrieveByFilter(filter *bson.D) ([]A, error)
	RetrieveWithLimit(filter *bson.D, limit int) ([]A, error)
	UpdateById(id *primitive.ObjectID) UpdateFn
	DeleteById(oid string) bool
}

type MongoCRUDRepo

type MongoCRUDRepo[A any] struct {
	Coll *mongo.Collection
	// contains filtered or unexported fields
}

func (MongoCRUDRepo[A]) Create

func (m MongoCRUDRepo[A]) Create(b A) (*mongo.InsertOneResult, error)

func (MongoCRUDRepo[A]) DeleteById

func (m MongoCRUDRepo[A]) DeleteById(id string) int64

func (*MongoCRUDRepo[A]) Init

func (it *MongoCRUDRepo[A]) Init(collectionName string) *MongoCRUDRepo[A]

func (MongoCRUDRepo[A]) RetrieveByFilter

func (m MongoCRUDRepo[A]) RetrieveByFilter(filter *bson.D) ([]A, error)

func (MongoCRUDRepo[A]) RetrieveById

func (m MongoCRUDRepo[A]) RetrieveById(oid primitive.ObjectID) *A

func (MongoCRUDRepo[A]) RetrieveWithLimit

func (m MongoCRUDRepo[A]) RetrieveWithLimit(filter *bson.D, limit int) ([]A, error)

func (MongoCRUDRepo[A]) UpdateById

func (m MongoCRUDRepo[A]) UpdateById(id *primitive.ObjectID) UpdateFn

type ReflectiveGet

type ReflectiveGet[C comparable] func(v reflect.Value) C

type UpdateFn

type UpdateFn func(d bson.D) (*mongo.UpdateResult, error)

Jump to

Keyboard shortcuts

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