Documentation ¶
Overview ¶
Package db is a database mechanism, which helps accessing data more convenient and efficient.
This mechanism provide two interfaces, Database and Factory, and you MUST implement these two interfaces to add your own database engine. Currently, zebra support ONLY MongoDB with driver mgo(http://labix.org/mgo).
Index ¶
- func Delete(collection string, args ...interface{}) error
- func Drop(db string, args ...interface{}) error
- func Insert(collection string, args ...interface{}) error
- func Ioctrl(cmd string, args ...interface{}) (interface{}, error)
- func Query(collection string, args ...interface{}) error
- func Register(uri string, factory Factory) error
- func UnRegister() error
- func Update(collection string, args ...interface{}) error
- func Use(db string) error
- type Database
- type FC
- type FD
- type Factory
- type MongoDB
- func (m *MongoDB) Count(collection string) int
- func (m *MongoDB) Delete(collection string, args ...interface{}) error
- func (m *MongoDB) Destroy() error
- func (m *MongoDB) Drop(db string, args ...interface{}) error
- func (m *MongoDB) Factory() Factory
- func (m *MongoDB) Insert(collection string, args ...interface{}) error
- func (m *MongoDB) Ioctrl(cmd string, args ...interface{}) (interface{}, error)
- func (m *MongoDB) Make(uri string) Database
- func (m *MongoDB) Query(collection string, args ...interface{}) error
- func (m *MongoDB) Update(collection string, args ...interface{}) error
- func (m *MongoDB) Use(db string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnRegister ¶
func UnRegister() error
Types ¶
type Database ¶
type Database interface { //Use change current active database Use(db string) error //Drop delete a database or table/collection of database Drop(db string, args ...interface{}) error //Insert add a data to database Insert(collection string, args ...interface{}) error //Delete remove a record from database Delete(collection string, args ...interface{}) error //Update update a record already in database Update(collection string, args ...interface{}) error //Query retrieve a record from database Query(collection string, args ...interface{}) error //Count returns total number of records in collection Count(collection string) int //Ioctrl implement other operations Ioctrl(cmd string, args ...interface{}) (interface{}, error) //Factory return a Factory interface instance, which can create and destroy a database engine Factory() Factory }
Database is interface which MUST be implemented to use zebra database mechanism
This interface provide several base operations for database access, such as, Insert, Delete, Update, Query , etc, with which you can access the data with unified APIs, and it's very convenient and efficient.
type FC ¶
type FC func(*mgo.Collection) (interface{}, error)
type Factory ¶
type Factory interface { //Make create a new database engine with URI string, which implemented Database interface. //URI string MUST like: mongodb://user:password@192.168.100.2:2014, depends on each implementation of engine Make(uri string) Database //Destroy destroy and cleanup engine instance if no further use Destroy() error }
Factory is a interface MUST be implemented to use zebra database mechanism
This interface provide two APIs to create and destroy database engine instance
type MongoDB ¶
func (*MongoDB) Factory ¶
Factory return a Factory interface instance, which can create and destroy a database engine
func (*MongoDB) Ioctrl ¶
Ioctrl implement other operations, cmd support "database" and "collection", if "database" specified, Ioctrl accept a function as second parameter, whose prototype MUST be func(*mgo.Database) (interface{}, error), and if "collection" specified, Ioctrl accept a collection name as second parameter, and a function as third parameter, whose prototype MUST be func(*mgo.Collection) (interface{}, error).