vmgo

package
v0.0.0-...-3b984fc Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseMongoConn

func CloseMongoConn()

CloseMongoConn - closes the mongodb connection

func Connect

func Connect(opts []*MongoConnOpts) (err error)

Connect - connects to one or more mirrors of mongodb server

func ConnectSingle

func ConnectSingle(opts *MongoConnOpts) (err error)

ConnectSingle - connects to single instance of mongodb server

func Count

func Count(dtype string, filter *vcmn.Filter) (count int, err error)

Count - counts the number of items for data type

func Create

func Create(dtype string, value interface{}) (err error)

Create - creates an record in 'dtype' collection

func Delete

func Delete(dtype string, matcher bson.M) (err error)

Delete - deletes record matched by the matcher from collection 'dtype'

func GenerateSelector

func GenerateSelector(filter *vcmn.Filter) (selector bson.M)

GenerateSelector - creates mongodb query for a generic filter

func Get

func Get(dtype string, matcher bson.M, out interface{}) (err error)

Get - gets a record matched by given matcher from collection 'dtype'

func GetAll

func GetAll(dtype string,
	sortFiled string,
	offset int,
	limit int,
	filter *vcmn.Filter,
	out interface{}) (err error)

GetAll - gets all the items from collection 'dtype' selected by filter & paged

func GetAllWithCount

func GetAllWithCount(dtype string,
	sortFiled string,
	offset int,
	limit int,
	filter *vcmn.Filter,
	out interface{}) (count int, err error)

GetAllWithCount - gets all the items from collection 'dtype' selected by filter & paged also gives the total count of items selected by filter

func GetCommands

func GetCommands() (cmds []cli.Command)

GetCommands - get list of commands for mongdb

func GetFilterValues

func GetFilterValues(
	dtype string,
	specs vcmn.FilterSpecList) (values bson.M, err error)

GetFilterValues - provides values associated the fields defined in filter spec

func GetFilterValuesX

func GetFilterValuesX(
	dtype string,
	field string,
	specs vcmn.FilterSpecList,
	filter *vcmn.Filter) (values bson.M, err error)

GetFilterValuesX - get values for filter based on given filter

func LogError

func LogError(module string, err error) (out error)

LogError - if error is not mog.ErrNotFound return null otherwise log the error and return the given error

func MakeRequireMongo

func MakeRequireMongo(cmd *cli.Command) *cli.Command

MakeRequireMongo - makes ccommand to require information that is needed to connect to a mongodb instance

func RegisterFactory

func RegisterFactory(dataType string, ff FactoryFunc)

RegisterFactory - registers factory functions for a data type

func SetDefaultDB

func SetDefaultDB(defDB string)

SetDefaultDB - sets the default DB

func Update

func Update(dtype string, matcher bson.M, value interface{}) (err error)

Update - updates the records in 'dtype' collection which are matched by the matcher query

Types

type FactoryFunc

type FactoryFunc func() StoredItem

FactoryFunc - Function for creating an instance of data type

type MongoConn

type MongoConn struct {
	*mgo.Database
}

MongoConn - represents a mongdb connection

func DefaultMongoConn

func DefaultMongoConn() *MongoConn

DefaultMongoConn - creates a connection to default DB

func NewMongoConn

func NewMongoConn(dbName string) (conn *MongoConn)

NewMongoConn - creates a new connection to mogodb

func (*MongoConn) Close

func (conn *MongoConn) Close()

Close - closes mongodb connection

type MongoConnOpts

type MongoConnOpts struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	User     string `json:"user"`
	Password string `json:"password"`
}

MongoConnOpts - options for connecting to a mongodb instance

type StoredItem

type StoredItem interface {
	ID() bson.ObjectId
	SetCreationInfo(at time.Time, by string)
	SetModInfo(at time.Time, by string)
}

StoredItem - represents a value that is stored in database and is compatible with generic queries and handlers. Any struct with a need to support generic CRUD operations must implement and register a factory method to return it

func Instance

func Instance(dataType string) StoredItem

Instance - creates and returns an instance of given data type

Jump to

Keyboard shortcuts

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