Documentation ¶
Index ¶
- Variables
- type BaseQuery
- func (q *BaseQuery) AddCriteria(expr bson.M)
- func (q *BaseQuery) GetCriteria() bson.M
- func (q *BaseQuery) GetLimit() int
- func (q *BaseQuery) GetSelect() Select
- func (q *BaseQuery) GetSkip() int
- func (q *BaseQuery) GetSort() Sort
- func (q *BaseQuery) Limit(l int)
- func (q *BaseQuery) Select(projection Select)
- func (q *BaseQuery) Skip(s int)
- func (q *BaseQuery) Sort(s Sort)
- func (q *BaseQuery) String() string
- type Dir
- type Document
- type DocumentBase
- type Field
- type FieldSelect
- type FieldSort
- type Filter
- type Map
- type Query
- type ResultSet
- type Select
- type Sort
- type Store
- func (s *Store) Count(q Query) (int, error)
- func (s *Store) Delete(doc DocumentBase) error
- func (s *Store) Find(q Query) (*ResultSet, error)
- func (s *Store) Insert(doc DocumentBase) error
- func (s *Store) MustCount(q Query) int
- func (s *Store) MustFind(q Query) *ResultSet
- func (s *Store) RawDelete(query Query, multi bool) error
- func (s *Store) RawUpdate(query Query, update interface{}, multi bool) error
- func (s *Store) Save(doc DocumentBase) (updated bool, err error)
- func (s *Store) Update(doc DocumentBase) error
Constants ¶
This section is empty.
Variables ¶
var ( //ErrResultSetClosed is throwed when you are working over a closed ResultSet ErrResultSetClosed = errors.New("closed resultset") //ErrNotFound document not found ErrNotFound = errors.New("document not found") // ErrStop if is used on a callback of a ResultSet.ForEach function the loop // is stopped ErrStop = errors.New("document not found") )
var ( // ErrNonNewDocument non-new documents cannot be inserted ErrNonNewDocument = errors.New("Cannot insert a non new document.") // ErrNewDocument a new documents cannot be updated ErrNewDocument = errors.New("Cannot updated a new document.") // ErrEmptyQueryInRaw an empty query cannot be used on any *Raw method ErrEmptyQueryInRaw = errors.New("Empty queries are not allowed on raw ops.") // ErrEmptyID a document without Id cannot be used with Save method ErrEmptyID = errors.New("A document without id is not allowed.") )
var (
IdField = NewField("_id", "bson.ObjectId")
)
Functions ¶
This section is empty.
Types ¶
type BaseQuery ¶
type BaseQuery struct {
// contains filtered or unexported fields
}
func NewBaseQuery ¶
func NewBaseQuery() *BaseQuery
func (*BaseQuery) AddCriteria ¶
AddCriteria adds a new mathing expression to the query, all the expressions are merged on a $and expression.
Use operators package instead of build expresion by hand:
import . "gopkg.in/src-d/storable.v1/operators" func (q *YourQuery) FindNonZeroRecords() { // All the Fields are defined on the Schema generated variable size := NewField("size", "int") q.AddCriteria(Gt(size, 0)) }
func (*BaseQuery) GetCriteria ¶
GetCriteria returns a valid bson.M used internally by Store.
func (*BaseQuery) Select ¶
Select specifies the fields to return using projection operators. http://docs.mongodb.org/manual/reference/operator/projection/
type Document ¶
type Document struct { Id bson.ObjectId `bson:"_id" json:"_id"` // contains filtered or unexported fields }
type DocumentBase ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
type FieldSelect ¶
type ResultSet ¶
type ResultSet struct { IsClosed bool // contains filtered or unexported fields }
ResultSet contains the result of an executed query command.
func (*ResultSet) All ¶
All returns all the documents in the ResultSet and close it. Dont use it with large results.
func (*ResultSet) Count ¶
Count returns the total number of documents in the ResultSet. Count DON'T close the ResultSet after be called.
type Select ¶
type Select []FieldSelect
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) Delete ¶
func (s *Store) Delete(doc DocumentBase) error
Delete remove the document from the collection
func (*Store) Insert ¶
func (s *Store) Insert(doc DocumentBase) error
Insert insert the given document in the collection, returns error if no-new document is given. The document id is setted if is empty.
func (*Store) RawDelete ¶
RawDelete performes a direct remove in the collection. If a query without criteria is given EmptyQueryInRawErr is returned
func (*Store) RawUpdate ¶
RawUpdate performes a direct update in the collection, update is wrapped on a $set operator. If a query without criteria is given EmptyQueryInRawErr is returned
func (*Store) Save ¶
func (s *Store) Save(doc DocumentBase) (updated bool, err error)
Save insert or update the given document in the collection, a document with id should be provided. Upsert is used (http://godoc.org/gopkg.in/mgo.v2#Collection.Upsert)
func (*Store) Update ¶
func (s *Store) Update(doc DocumentBase) error
Update update the given document in the collection, returns error if a new document is given.