Documentation
¶
Index ¶
- Variables
- func AddEntryToStats(stats map[string]interface{}, entry map[string]interface{}, fields []string) error
- func ExtractTopLevel(fields []string) []string
- func GetDefaultStats() map[string]interface{}
- func RemoveTopLevel(fields []string) []string
- func UpdateStatsField(stats map[string]interface{}, key string, value interface{}) error
- type ChangeResults
- type Database
- type MongoDatabase
- func (db *MongoDatabase) Close()
- func (db *MongoDatabase) Connect(host string) error
- func (db *MongoDatabase) DropDatabase() error
- func (db *MongoDatabase) FindAll(collection_name string, query interface{}, result interface{}) error
- func (db *MongoDatabase) FindOne(collection_name string, query interface{}, result interface{}) error
- func (db *MongoDatabase) GetSession() *mgo.Session
- func (db *MongoDatabase) GetStats(collection_name string, fields []string) (map[string]interface{}, error)
- func (db *MongoDatabase) Insert(collection_name string, item interface{}) error
- func (db *MongoDatabase) RemoveAll(collection_name string, query interface{}) (*ChangeResults, error)
- func (db *MongoDatabase) RemoveOne(collection_name string, query interface{}) error
- func (db *MongoDatabase) Update(collection_name string, selector interface{}, update interface{}) error
- func (db *MongoDatabase) UpdateAll(collection_name string, selector interface{}, update interface{}) (*ChangeResults, error)
- func (db *MongoDatabase) Upsert(collection_name string, selector interface{}, update interface{}) (*ChangeResults, error)
- type QuerySelector
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("Error: NOT_FOUND") ErrConnection = errors.New("Error: CONNECTION_FAILED") ErrUnknown = errors.New("Error: UNKNOWN") )
var ErrTypeMismatch = errors.New("Error: TYPE_MISMATCH")
Functions ¶
func AddEntryToStats ¶
func AddEntryToStats(stats map[string]interface{}, entry map[string]interface{}, fields []string) error
Updates the stats with the given entry
func ExtractTopLevel ¶ added in v0.4.0
Remove everything in each field after, and including, the first '.'
func GetDefaultStats ¶
func GetDefaultStats() map[string]interface{}
Returns a maps of default stats
func RemoveTopLevel ¶ added in v0.4.0
Remove everything in each field before, and including, the first '.'
func UpdateStatsField ¶
Types ¶
type ChangeResults ¶
Used to store information about the changes made by a database operation
type Database ¶
type Database interface { Connect(host string) error Close() FindOne(collection_name string, query interface{}, result interface{}) error FindAll(collection_name string, query interface{}, result interface{}) error RemoveOne(collection_name string, query interface{}) error RemoveAll(collection_name string, query interface{}) (*ChangeResults, error) Insert(collection_name string, item interface{}) error Upsert(collection_name string, selector interface{}, update interface{}) (*ChangeResults, error) Update(collection_name string, selector interface{}, update interface{}) error UpdateAll(collection_name string, selector interface{}, update interface{}) (*ChangeResults, error) DropDatabase() error GetStats(collection_name string, fields []string) (map[string]interface{}, error) }
Database interface exposing the methods necessary to querying, inserting, updating, upserting, and removing records
type MongoDatabase ¶
type MongoDatabase struct {
// contains filtered or unexported fields
}
MongoDatabase struct which implements the Database interface for a mongo database
func InitMongoDatabase ¶
func InitMongoDatabase(host string, db_name string) (*MongoDatabase, error)
Initialize connection to mongo database
func (*MongoDatabase) Close ¶ added in v0.3.0
func (db *MongoDatabase) Close()
Close the global session to the given mongo database
func (*MongoDatabase) Connect ¶
func (db *MongoDatabase) Connect(host string) error
Open a session to the given mongo database
func (*MongoDatabase) DropDatabase ¶
func (db *MongoDatabase) DropDatabase() error
Drops the entire database
func (*MongoDatabase) FindAll ¶
func (db *MongoDatabase) FindAll(collection_name string, query interface{}, result interface{}) error
Find all elements matching the given query parameters
func (*MongoDatabase) FindOne ¶
func (db *MongoDatabase) FindOne(collection_name string, query interface{}, result interface{}) error
Find one element matching the given query parameters
func (*MongoDatabase) GetSession ¶
func (db *MongoDatabase) GetSession() *mgo.Session
Returns a copy of the global session for use by a connection
func (*MongoDatabase) GetStats ¶
func (db *MongoDatabase) GetStats(collection_name string, fields []string) (map[string]interface{}, error)
Returns a map of statistics for a given collection
func (*MongoDatabase) Insert ¶
func (db *MongoDatabase) Insert(collection_name string, item interface{}) error
Insert the given item into the collection
func (*MongoDatabase) RemoveAll ¶
func (db *MongoDatabase) RemoveAll(collection_name string, query interface{}) (*ChangeResults, error)
Remove all elements matching the given query parameters
func (*MongoDatabase) RemoveOne ¶
func (db *MongoDatabase) RemoveOne(collection_name string, query interface{}) error
Remove one element matching the given query parameters
func (*MongoDatabase) Update ¶
func (db *MongoDatabase) Update(collection_name string, selector interface{}, update interface{}) error
Finds an item based on the given selector and updates it with the data in update
func (*MongoDatabase) UpdateAll ¶
func (db *MongoDatabase) UpdateAll(collection_name string, selector interface{}, update interface{}) (*ChangeResults, error)
Finds all items based on the given selector and updates them with the data in update
func (*MongoDatabase) Upsert ¶
func (db *MongoDatabase) Upsert(collection_name string, selector interface{}, update interface{}) (*ChangeResults, error)
Upsert the given item into the collection i.e., if the item exists, it is updated with the given values, else a new item with those values is created.
type QuerySelector ¶
type QuerySelector map[string]interface{}
An alias of a string -> interface{} map used for database queries and selectors