modelsv2

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(db *mongo.Database, model Model, extra *AggregateOpts) ([]interface{}, error)

Aggregate method will aggregate the collection and return the results accordingly

func ConvertID

func ConvertID(id string) primitive.ObjectID

ConvertID method will try to convert given string to BSON Object ID

func ConvertIDs

func ConvertIDs(ids []string) []primitive.ObjectID

ConvertIDs method will try to convert given slice to BSON Object ID slice

func CountDocs

func CountDocs(db *mongo.Database, model Model, query bson.M) int64

CountDocs method will count the documents in a table based on query supplied

func DateQuery

func DateQuery(start, end time.Time) bson.M

DateQuery will return the bson representation to query daterange between 2 time intervals

func DeleteMany

func DeleteMany(db *mongo.Database, model Model, query bson.M) bool

DeleteMany method will delete multiple documents based on the filter

func DeleteOne

func DeleteOne(db *mongo.Database, model Model, query bson.M) bool

DeleteOne method will delete a single document based on the query

func EmptyMongoID

func EmptyMongoID() primitive.ObjectID

EmptyMongoID method will return an objectID which is empty

func FindAll

func FindAll(db *mongo.Database, model Model, query bson.M, queryOpts *FindOptions) []interface{}

FindAll will try to find the documents based on the query

func FindByID

func FindByID(coll *mongo.Collection, id string) *mongo.SingleResult

FindByID method will try to find the document in collection with given id

func GetCacheKey

func GetCacheKey(model Model, id string) string

GetCacheKey method returns the cache key for model with id

func InsertMany

func InsertMany(db *mongo.Database, model Model, docs []interface{}) ([]interface{}, error)

InsertMany method will insert documents in bulk inside the collection

func NewMongoID

func NewMongoID() primitive.ObjectID

NewMongoID method will return a new BSON Objec ID

func Query

func Query(db *mongo.Database, model Model, query bson.M, queryOpts *FindOptions) (*mongo.Cursor, error)

Query method will return cursor to the database

func Save

func Save(db *mongo.Database, cacheClient *cache.MultiClient, model Model, id string) error

Save method will save the document in db and update the cache

func ToJSON

func ToJSON(m Model) string

ToJSON method will convert the model to json string

func UpdateMany

func UpdateMany(db *mongo.Database, model Model, query, updateObj bson.M) error

UpdateMany will update the rows of the table based on the query supplied

Types

type AggregateOpts

type AggregateOpts struct {
	Match, Group bson.M
	Project      []string
	MaxTime      time.Duration
	Limit        int
}

AggregateOpts method is used for holding options while doing aggregation

type FindOptions

type FindOptions struct {
	Sort, Hint  interface{}
	Projection  interface{}
	Limit, Skip *int64
	BatchSize   *int32
	Timeout     time.Duration
}

FindOptions struct will contain the additional find information

type Model

type Model interface {
	New() Model
	Table() string
	IsEmpty() bool
	FindByID(db *mongo.Database, id string) Model
	ClearCacheData(cacheClient *cache.MultiClient)
}

Model interface is a generic type for all the models

func CacheFirst

func CacheFirst(cacheClient *cache.MultiClient, db *mongo.Database, model Model, id string) Model

CacheFirst method will try to find the object with given id in cache else it will query the db and save the result in cache

func FindOne

func FindOne(db *mongo.Database, model Model, query bson.M) Model

FindOne method will try to find the object with given query

func FindOneWithOpts

func FindOneWithOpts(db *mongo.Database, model Model, query bson.M, queryOpts *FindOptions) Model

FindOneWithOpts method will try to find the object based on the query and options

Jump to

Keyboard shortcuts

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