Documentation ¶
Index ¶
- Constants
- Variables
- func Close(conn *Connection) error
- type BulkInsertStruct
- type Callback
- type Config
- type Connection
- func (conn *Connection) BulkInsert(bulkInsertStruct *BulkInsertStruct) (*mgo.BulkResult, error)
- func (conn *Connection) Find(findStruct *FindStruct) ([]interface{}, error)
- func (conn *Connection) FindAll(findAllStruct *FindAllStruct) ([]interface{}, error)
- func (conn *Connection) FindAllAsync(findAllStruct *FindAllStruct, callback chan *Callback)
- func (conn *Connection) FindAsync(findStruct *FindStruct, callback chan *Callback)
- func (conn *Connection) FindByID(findByIDStruct *FindByIDStruct) (interface{}, error)
- func (conn *Connection) FindByIDAsync(findByIDStruct *FindByIDStruct, callback chan *Callback)
- func (conn *Connection) Insert(insertStruct *InsertStruct) error
- func (conn *Connection) InsertAsync(insertStruct *InsertStruct, callback chan *Callback)
- func (conn *Connection) Remove(removeStruct *RemoveStruct) error
- func (conn *Connection) RemoveAll(removeAllStruct *RemoveAllStruct) (*mgo.ChangeInfo, error)
- func (conn *Connection) RemoveAllAsync(removeAllStruct *RemoveAllStruct, callback chan *Callback)
- func (conn *Connection) RemoveAsync(removeStruct *RemoveStruct, callback chan *Callback)
- func (conn *Connection) Update(updateStruct *UpdateStruct) error
- func (conn *Connection) UpdateAll(updateAllStruct *UpdateAllStruct) (*mgo.ChangeInfo, error)
- func (conn *Connection) UpdateAllAsync(updateAllStruct *UpdateAllStruct, callback chan *Callback)
- func (conn *Connection) UpdateAsync(updateStruct *UpdateStruct, callback chan *Callback)
- func (conn *Connection) Upsert(upsertStruct *UpsertStruct) (*mgo.ChangeInfo, error)
- func (conn *Connection) UpsertAll(upsertAllStruct *UpsertAllStruct) (*mgo.ChangeInfo, error)
- func (conn *Connection) UpsertAllAsync(upsertAllStruct *UpsertAllStruct, callback chan *Callback)
- func (conn *Connection) UpsertAsync(upsertStruct *UpsertStruct, callback chan *Callback)
- type DB
- type FindAllStruct
- type FindByIDStruct
- type FindStruct
- type InsertStruct
- type MongoDB
- type Operations
- type RemoveAllStruct
- type RemoveStruct
- type UpdateAllStruct
- type UpdateStruct
- type UpsertAllStruct
- type UpsertStruct
Constants ¶
const ( MYSQL = "mysql" SQLITE = "sqlite" MONGODB = "mongodb" )
Our Database types types
Variables ¶
var ( MongoErrorNotFound = errors.New("not found") //especiall for mongo not found error | that's why "n" is in small letters | dont change it ErrorNotFound = errors.New("Data not found") ErrorInvalidDBType = errors.New("Invalid database type") ErrorInvalidDriver = errors.New("Unsupported storage driver!") )
Functions ¶
func Close ¶
func Close(conn *Connection) error
Types ¶
type BulkInsertStruct ¶
type BulkInsertStruct struct { Config *Config Data []interface{} }
type Connection ¶
type Connection struct { Database string //database name DialInfo *mgo.DialInfo // connection info Session *mgo.Session //session info Collections map[string]*mgo.Collection //all collections Collection string //collection name }
func (*Connection) BulkInsert ¶
func (conn *Connection) BulkInsert(bulkInsertStruct *BulkInsertStruct) (*mgo.BulkResult, error)
BulkInsert : Function inserts the data in bulk to the collection Input Parameters :
*BulkInsertStruct (Struct) : Data([] interfaces{}]) : the object which has to be inserted
Output Parameters
record(*mgo.BulkResult) : return count of matched and modified results error : if it was error then return error else nil
func (*Connection) Find ¶
func (conn *Connection) Find(findStruct *FindStruct) ([]interface{}, error)
Find : Function finds the record into the collection according to the query/criteria Input Parameters
*FindStruct (Struct) : Query(bson Object) : Criteria as per the update should execute Options(map[string]int) : optional things like, limit, skip, etc
Output Parameters
records([]interface{]}) : Return the result mapped as interface error(error) : if it was error then return error else nil
func (*Connection) FindAll ¶
func (conn *Connection) FindAll(findAllStruct *FindAllStruct) ([]interface{}, error)
FindAll : Function finds all the records into the collection Input Parameters
*FindAllStruct (Struct) :
Output Parameters
records([]interface{}) : all the records present in database error : if it was error then return error else nil
func (*Connection) FindAllAsync ¶
func (conn *Connection) FindAllAsync(findAllStruct *FindAllStruct, callback chan *Callback)
FindAllAsync : Function finds all the records into the collection Input Parameters
*FindAllStruct (Struct) : callback (channel) : which returns data to goroutine
Output Parameters
callback(data, error) : returns data, error to channel
func (*Connection) FindAsync ¶
func (conn *Connection) FindAsync(findStruct *FindStruct, callback chan *Callback)
FindAsync : Function finds the record into the collection according to the query/criteria Input Parameters
*FindStruct (Struct) : Query(bson Object) : Criteria as per the update should execute Options(map[string]int) : optional things like, limit, skip, etc callback (channel) : which returns data to goroutine
Output Parameters
callback(data, error) : returns data, error to channel
func (*Connection) FindByID ¶
func (conn *Connection) FindByID(findByIDStruct *FindByIDStruct) (interface{}, error)
FindByID : Function FindByID finds and returns record by Hexadecimal ID Input Parameters :
*FindByIDStruct (Struct) : Id(string) : The record id whose details have to be updated
Output :
record(interface{}) : Returns the mongo Object error : Return error object if found
func (*Connection) FindByIDAsync ¶
func (conn *Connection) FindByIDAsync(findByIDStruct *FindByIDStruct, callback chan *Callback)
FindByIDAsync : Function FindByIDAsync finds and returns record by Hexadecimal ID Input Parameters :
*FindByIDStruct (Struct) : Id(string) : The record id whose details have to be updated callback (channel) : which returns data to goroutine
Output :
callback(data, error) : sends data, error to channel
func (*Connection) Insert ¶
func (conn *Connection) Insert(insertStruct *InsertStruct) error
Insert : Function inserts the data object into the collection Input Parameters :
*InsertStruct (Struct) : Data([] interfaces{}]) : the object which has to be inserted
Output Parameters
error : if it was error then return error else nil
func (*Connection) InsertAsync ¶
func (conn *Connection) InsertAsync(insertStruct *InsertStruct, callback chan *Callback)
InsertAsync : Function inserts the data object into the collection Input Parameters :
*InsertStruct (Struct) : Data([] interfaces{}]) : the object which has to be inserted callback (channel) : which returns data to goroutine
Output Parameters
callback(data, error) : sends data, error back to channel
func (*Connection) Remove ¶
func (conn *Connection) Remove(removeStruct *RemoveStruct) error
Remove : Function removes the record from the collection as per criteria/query Input Parameters
*RemoveStruct (Struct) : Query(bson Object) : Criteria as per the update should execute
Output Parameters
records(boolean) : returns true / false depending on output of operation error : if it was error then return error else nil
func (*Connection) RemoveAll ¶
func (conn *Connection) RemoveAll(removeAllStruct *RemoveAllStruct) (*mgo.ChangeInfo, error)
RemoveAll : Function removes all the record from the collection Input Parameters
*RemoveAllStruct (Struct) :
Output Parameters
records(*mgo.ChangeInfo) : returns matched modified removed count error : if it was error then return error else nil
func (*Connection) RemoveAllAsync ¶
func (conn *Connection) RemoveAllAsync(removeAllStruct *RemoveAllStruct, callback chan *Callback)
RemoveAllAsync : Function removes all the record from the collection asynchronously Input Parameters
*RemoveAllStruct (Struct) : callback (channel) : which returns data to goroutine
Output Parameters
callback(data, error) : returns data, error to channel
func (*Connection) RemoveAsync ¶
func (conn *Connection) RemoveAsync(removeStruct *RemoveStruct, callback chan *Callback)
removeAsync : Function removes the record from the collection as per criteria/query Input Parameters
*RemoveStruct (Struct) : Query(bson Object) : Criteria as per the update should execute callback (channel) : which returns data to goroutine
Output Parameters
callback(data, error) : returns data, error to channel
func (*Connection) Update ¶
func (conn *Connection) Update(updateStruct *UpdateStruct) error
func (*Connection) UpdateAll ¶
func (conn *Connection) UpdateAll(updateAllStruct *UpdateAllStruct) (*mgo.ChangeInfo, error)
func (*Connection) UpdateAllAsync ¶
func (conn *Connection) UpdateAllAsync(updateAllStruct *UpdateAllStruct, callback chan *Callback)
func (*Connection) UpdateAsync ¶
func (conn *Connection) UpdateAsync(updateStruct *UpdateStruct, callback chan *Callback)
UpdateAsync : Function Updates the record into the collection Input Parameters
*UpdateStruct (Struct) : Data([] interfaces{}]) : the object which has to be inserted Id(string) : The record id whose details have to be updated callback (channel) : which returns data to goroutine
Output Parameters
callback(data, error) : sends if error back to channel
func (*Connection) Upsert ¶
func (conn *Connection) Upsert(upsertStruct *UpsertStruct) (*mgo.ChangeInfo, error)
func (*Connection) UpsertAll ¶
func (conn *Connection) UpsertAll(upsertAllStruct *UpsertAllStruct) (*mgo.ChangeInfo, error)
func (*Connection) UpsertAllAsync ¶
func (conn *Connection) UpsertAllAsync(upsertAllStruct *UpsertAllStruct, callback chan *Callback)
func (*Connection) UpsertAsync ¶
func (conn *Connection) UpsertAsync(upsertStruct *UpsertStruct, callback chan *Callback)
type DB ¶
type DB interface {
Connect(*Config) (*Connection, error)
}
type FindAllStruct ¶
type FindByIDStruct ¶
type InsertStruct ¶
type InsertStruct struct {
Data interface{}
}
type Operations ¶
type Operations interface { BulkInsertStruct(*BulkInsertStruct) Insert(*InsertStruct) error InsertAsync(*InsertStruct, *Callback) Update(*UpdateStruct) error UpdateAsync(*UpdateStruct, *Callback) Upsert(*UpsertStruct) (*mgo.ChangeInfo, error) UpsertAsync(*UpsertStruct, *Callback) UpdateAll(*UpdateAllStruct) (*mgo.ChangeInfo, error) UpdateAllAsync(*UpdateAllStruct, *Callback) UpsertAll(*UpsertAllStruct) (*mgo.ChangeInfo, error) UpsertAllAsync(*UpsertAllStruct, *Callback) FindByID(*FindByIDStruct) (interface{}, error) FindByIDAsync(*FindByIDStruct, *Callback) Find(*FindStruct) ([]interface{}, error) FindAsync(*FindStruct, *Callback) FindAll(*FindAllStruct) ([]interface{}, error) FindAllAsync(*FindAllStruct, *Callback) Remove(*RemoveStruct) error RemoveAsync(*RemoveStruct, *Callback) RemoveAll(*RemoveAllStruct) (*mgo.ChangeInfo, error) RemoveAllAsync(*RemoveAllStruct, *Callback) }
type RemoveAllStruct ¶
type RemoveAllStruct struct { }
type RemoveStruct ¶
type UpdateAllStruct ¶
type UpdateStruct ¶
type UpdateStruct struct { Id string Data interface{} }
type UpsertAllStruct ¶
type UpsertStruct ¶
type UpsertStruct struct { Id string Data interface{} }