Documentation ¶
Index ¶
- func Setup(dbConfig DbConfig) error
- type Db
- type DbConfig
- type DbSession
- func (s *DbSession) Clone() *DbSession
- func (s *DbSession) Close()
- func (s *DbSession) Collection(d Document) *mgo.Collection
- func (s *DbSession) DocumentIterator(query Q, collection string) *DocumentIterator
- func (s *DbSession) Exists(query Q, document Document) (bool, error)
- func (s *DbSession) Find(query Q, document Document) error
- func (s *DbSession) FindAll(query Q, document Document) (interface{}, error)
- func (s *DbSession) FindAllWithFields(query Q, fields []string, document Document) (interface{}, error)
- func (s *DbSession) FindByID(id string, result Document) error
- func (s *DbSession) FindByRef(ref *mgo.DBRef, document Document) error
- func (s *DbSession) FindWithLimit(limit int, query Q, document Document) (interface{}, error)
- func (s *DbSession) Pipe(pipeline interface{}, document Document) *mgo.Pipe
- func (s *DbSession) ReadFile(id, prefix string, file *File) error
- func (s *DbSession) Remove(query Q, document Document) error
- func (s *DbSession) RemoveAll(query Q, document Document) error
- func (s *DbSession) Save(document Document) error
- func (s *DbSession) SaveFile(file File, prefix string) (string, error)
- func (s *DbSession) Update(selector Q, document Document) error
- func (s *DbSession) UpdateFieldValue(query Q, collectionName, field string, value interface{}) error
- type Document
- type DocumentIterator
- func (pd *DocumentIterator) All(document Document) (interface{}, error)
- func (pd *DocumentIterator) Close() error
- func (pd *DocumentIterator) Error() error
- func (pd *DocumentIterator) FetchNext(d interface{}) bool
- func (pd *DocumentIterator) HasMore() bool
- func (pd *DocumentIterator) IsTimeout() bool
- func (pd *DocumentIterator) Load(cfg IteratorConfig)
- func (pd *DocumentIterator) Next(d Document) error
- type File
- type IteratorConfig
- type MongoTail
- type Q
- type TailEvent
- type TailEventHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Db ¶
type Db struct { Config DbConfig // contains filtered or unexported fields }
Db represents database connection which holds reference to global session and configuration for that database.
type DbSession ¶
DbSession mgo session wrapper
func (*DbSession) Clone ¶
Clone returns the clone of current DB session. Cloned session uses the same socket connection
func (*DbSession) Collection ¶
func (s *DbSession) Collection(d Document) *mgo.Collection
Collection returns a mgo.Collection representation for given document
func (*DbSession) DocumentIterator ¶
func (s *DbSession) DocumentIterator(query Q, collection string) *DocumentIterator
DocumentIterator returns the document iterator which could be used to fetch documents as batch with batch size and other config params
func (*DbSession) FindAllWithFields ¶
func (s *DbSession) FindAllWithFields(query Q, fields []string, document Document) (interface{}, error)
FindAllWithFields returns all the documents with given fields based on a given query
func (*DbSession) FindByID ¶
FindByID find the object by id. Returns error if it's not able to find the document. If document is found it's copied to the passed in result object.
func (*DbSession) FindWithLimit ¶
FindWithLimit find the doucments for given query with limit
func (*DbSession) Save ¶
Save inserts the given document that represents the collection to the database.
type Document ¶
type Document interface {
CollectionName() string
}
Document interface implemented by structs that needs to be persisted. It should provide collection name, as in the database. Also, a way to create new object id before saving.
type DocumentIterator ¶
type DocumentIterator struct {
// contains filtered or unexported fields
}
DocumentIterator is used to iterate over results and also provides a way to configure query using IteractorConfig For example:
session := db.Session() defer session.Close() pd := session.DocumentIterator(gmgo.Q{"state":"CA"}, "user") pd.Load(gmgo.IteratorConfig{PageSize: 200, Snapshot: true}) for pd.HasMore() { usr := new(user) result, err := pd.Next(&usr) if err != nil { println(err.Error()) return } u := result.(*user) }
func (*DocumentIterator) All ¶
func (pd *DocumentIterator) All(document Document) (interface{}, error)
All returns all the documents in the iterator.
func (*DocumentIterator) Close ¶
func (pd *DocumentIterator) Close() error
Close closes the document iterator
func (*DocumentIterator) Error ¶
func (pd *DocumentIterator) Error() error
Error returns iteration error
func (*DocumentIterator) FetchNext ¶
func (pd *DocumentIterator) FetchNext(d interface{}) bool
FetchNext retrieves the next document from the result set. For more details see mgo.Iter.Next() return false if there are no more records to fetch
Usage:
aitr := session.DocumentIterator(gmgo.Q{}, data.User{}.CollectionName()) aitr.Load(gmgo.IteratorConfig{PageSize: 1000, SortBy: []string{"-_id"}}) var usr *data.User for aitr.FetchNext(&usr) { fmt.Printf("ID: %s", usr.Id) } //check if error happend err := aitr.Error() if err != nil { fmt.Printf("handle error: %s", err) } //check if timeout happened if aitr.IsTimeOut() { -- handle timeout }
func (*DocumentIterator) HasMore ¶
func (pd *DocumentIterator) HasMore() bool
HasMore returns true if paged document has still more documents to fetch. DEPRECATED Use FetchNext in favor of this
func (*DocumentIterator) IsTimeout ¶
func (pd *DocumentIterator) IsTimeout() bool
IsTimeout returns true if the iterator timed out
func (*DocumentIterator) Load ¶
func (pd *DocumentIterator) Load(cfg IteratorConfig)
Load loads the document iterator using IteratorConfig For example: Limit and sort by user full name
itr := session.DocumentIterator(Q{"state": "CA"}, new(user)) itr.Load(IteratorConfig{Limit: 20, SortBy: []string{"fullName"}})
fetch with page size
pd.Load(IteratorConfig{PageSize: 200})
func (*DocumentIterator) Next ¶
func (pd *DocumentIterator) Next(d Document) error
Next returns the next result object in the paged document. If there's no element it will check for error and return the error if there's error. DEPRECATED - Use FetchNext in favor of this
type IteratorConfig ¶
type IteratorConfig struct { //PageSize is used as a batch size. See mgo.Iter.Batch() for more details. //Default value used by MongoDB is 100. So, any value less than 100 is ignored PageSize int //Limit used limit the number of documents Limit int //Snashopt ($snapshot) operator prevents the cursor from returning a document more than //once because an intervening write operation results in a move of the document. Snapshot bool //SortBy list of field names to sort the result SortBy []string }
IteratorConfig defines different iterator config to load the document interator
type MongoTail ¶
type MongoTail struct { EventHandler TailEventHandler ReImport bool }
MongoTail handles MongoDB tailing event coordination and also update destination dbs