mgoHelpers

package module
v0.0.0-...-b913a59 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetObjectIDFromString

func GetObjectIDFromString(s string) (bson.ObjectId, error)

Types

type DbEntryBase

type DbEntryBase struct {
	ID bson.ObjectId `bson:"_id,omitempty" json:"objectid"`
}

func (*DbEntryBase) BsonID

func (e *DbEntryBase) BsonID() bson.ObjectId

func (*DbEntryBase) SetBsonID

func (e *DbEntryBase) SetBsonID(id bson.ObjectId)

type EntryErrorPair

type EntryErrorPair struct {
	Entry MongoEntry
	Error error
}

type EntryErrorPairs

type EntryErrorPairs []EntryErrorPair

func (*EntryErrorPairs) CheckPartFail

func (p *EntryErrorPairs) CheckPartFail() bool

func (*EntryErrorPairs) MakeEntrySlice

func (p *EntryErrorPairs) MakeEntrySlice() []MongoEntry

type MongoCollection

type MongoCollection struct {
	sync.Mutex
	MongoStorageInfo
	// contains filtered or unexported fields
}

MongoCollection represents abstact collection in MongoDB. It supports CRUD but should not be used directly. Instead you have to write a wrapper for your own data type.

func NewMongoCollection

func NewMongoCollection(dbInstance *MongoDb, collName string) *MongoCollection

NewMongoCollection creates a new instance of the MongoDB collection.

func (*MongoCollection) Create

func (c *MongoCollection) Create(factoryFuncParams interface{}) (entry MongoEntry, err error)

Create creates a new entry from specified param and factory function and inserts it into database. Please note that unless your factory depends on items in the collection you should run Insert instead.

func (*MongoCollection) CreateBulk

func (c *MongoCollection) CreateBulk(factoryFuncParamSet []interface{}) (entries []MongoEntry, err error)

func (*MongoCollection) Delete

func (c *MongoCollection) Delete(entryID string) (status error)

Delete removes entry from the database.

func (*MongoCollection) DeleteAll

func (c *MongoCollection) DeleteAll() (status error)

DeleteAll removes all entries from the collection.

func (*MongoCollection) Insert

func (c *MongoCollection) Insert(entry MongoEntry) (err error)

Insert adds a ready-made entry into the database.

func (*MongoCollection) InsertBulk

func (c *MongoCollection) InsertBulk(entries []MongoEntry) (err error)

func (*MongoCollection) MutexExec

func (c *MongoCollection) MutexExec(cb func())

func (*MongoCollection) Read

func (c *MongoCollection) Read(entryID string, result MongoEntry) bool

Read returns the entry that matches specified entry ID.

func (*MongoCollection) ReadAll

func (c *MongoCollection) ReadAll(result interface{}) (err error)

ReadAll returns all entries in the database. The first argument *must* be a pointer to a slice.

func (*MongoCollection) SetFactoryFunc

func (c *MongoCollection) SetFactoryFunc(factoryFunc func(*MongoCollection, interface{}) MongoEntry)

SetFactoryFunc sets the object factory function used by Create for creation of new objects.

func (*MongoCollection) Update

func (c *MongoCollection) Update(entryID string, factoryFuncParam interface{}) (entry MongoEntry, status error)

Update modifies entry based on input parameters.

type MongoDb

type MongoDb struct {
	// contains filtered or unexported fields
}

func GetDb

func GetDb() *MongoDb

func (*MongoDb) Connect

func (db *MongoDb) Connect(dsn string) error

func (*MongoDb) Disconnect

func (db *MongoDb) Disconnect()

func (*MongoDb) Find

func (db *MongoDb) Find(coll string, query map[string]interface{}, v interface{}) error

func (*MongoDb) FindAll

func (db *MongoDb) FindAll(coll string, v interface{}) error

func (*MongoDb) FindById

func (db *MongoDb) FindById(coll string, id string, v interface{}) bool

func (*MongoDb) Insert

func (db *MongoDb) Insert(coll string, v ...interface{}) error

func (*MongoDb) Remove

func (db *MongoDb) Remove(coll string, id interface{}) error

func (*MongoDb) RemoveAll

func (db *MongoDb) RemoveAll(coll string) error

func (*MongoDb) SessExec

func (db *MongoDb) SessExec(cb func(*mgo.Session))

func (*MongoDb) Update

func (db *MongoDb) Update(coll string, id interface{}, v interface{}) error

type MongoEntry

type MongoEntry interface {
	BsonID() bson.ObjectId
	SetBsonID(bson.ObjectId)
}

type MongoStorageInfo

type MongoStorageInfo struct {
	Database   *MongoDb
	Collection string
}

Jump to

Keyboard shortcuts

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