Documentation ¶
Index ¶
- Constants
- Variables
- type Change
- type ChangeOp
- type DelQuery
- type DelResponse
- type Filter
- type Filters
- type GetQuery
- func (q *GetQuery) All() *GetQuery
- func (q *GetQuery) Fields(props ...string) *GetQuery
- func (q *GetQuery) Filter(prop, op string, values ...interface{}) *GetQuery
- func (q *GetQuery) FilterBetween(prop string, min, max interface{}) *GetQuery
- func (q *GetQuery) FilterEq(prop string, value interface{}) *GetQuery
- func (q *GetQuery) FilterIn(prop string, values ...interface{}) *GetQuery
- func (q *GetQuery) Limit(limit int) *GetQuery
- func (q GetQuery) Load(c client.Client, dst interface{}) (int, error)
- func (q *GetQuery) OrderBy(prop string, mode SortMode) *GetQuery
- func (q *GetQuery) Page(offset, limit int) *GetQuery
- func (q GetQuery) String() string
- func (q GetQuery) Validate() error
- type GetResponse
- type Ordering
- type Paging
- type PingQuery
- type PingResponse
- type PutQuery
- type PutResponse
- type Query
- type QueryResult
- type Response
- type SortMode
- type UpdateQuery
- func (q *UpdateQuery) DelProperty(prop string) *UpdateQuery
- func (q *UpdateQuery) Expire(ttl time.Duration) *UpdateQuery
- func (q *UpdateQuery) Increment(prop string, newVal int64) *UpdateQuery
- func (q *UpdateQuery) Set(prop string, newVal interface{}) *UpdateQuery
- func (q *UpdateQuery) Validate() (err error)
- func (q *UpdateQuery) Where(prop string, operator string, values ...interface{}) *UpdateQuery
- func (q *UpdateQuery) WhereEquals(prop string, values ...interface{}) *UpdateQuery
- func (q *UpdateQuery) WhereId(ids ...interface{}) *UpdateQuery
- type UpdateResponse
Constants ¶
const ( In = "IN" Eq = "=" Gt = ">" Lt = "<" Between = "><" All = "ALL" )
Variables ¶
var DefaultPagingLimit = 100
This sets the deault limit for queries that don't have limit built into them
var NoOrder = Ordering{Ascending: true}
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct { Property string `bson:"property"` Value interface{} `bson:"value"` Op ChangeOp `bson:"op"` }
Change represents a single change in an UPDATE query- what property is being updated, how and to what value
func DelProperty ¶
DelProperty is an UPDATE change that deletes a single property from an entity
func IncrementFloat ¶
IncrementFloat returns a new Incr for a property with a given float value. Should be used only on float properties
type ChangeOp ¶
type ChangeOp string
ChangeOp is a wrapper to a string, making sure you don't accidentally put random strings into changes
const ( OpSet ChangeOp = "SET" // Delete an entire entity OpDel ChangeOp = "DEL" OpExpire ChangeOp = "EXP" OpIncrement ChangeOp = "INCR" OpSetAdd ChangeOp = "SADD" OpSetDel ChangeOp = "SDEL" OpMapSet ChangeOp = "MSET" OpMapDel ChangeOp = "MDEL" // Delete a single property of an entity OpPropDel ChangeOp = "PDEL" // noop is a special internal OP that is used for reindexing entities. // it is not valid in a client request Noop ChangeOp = "NOOP" )
Constants for chanbge Ops
type DelQuery ¶
DelQuery represents a DEL request handled by the appropriate driver
func NewDelQuery ¶
NewDelQuery creates a new query object for a given table
type DelResponse ¶
DelResponse represents a response to a DEL query over the protocol, with the usual resonse properties, and the number of objects deleted
func NewDelResponse ¶
func NewDelResponse(err error, num int) *DelResponse
NewDelResponse creates a new response to be returned by the protocol with the given error and number of objects deleted
type Filter ¶
type Filter struct { Property string `bson:"property"` Operator string `bson:"op"` Values []interface{} `bson:"values"` }
type GetQuery ¶
type GetQuery struct { Table string `bson:"table"` Properties []string `bson:"properties"` Filters Filters `bson:"filters"` Order Ordering `bson:"order"` Paging Paging `bson:"paging"` }
GetQuery describes and build a query to get objects from the database.
It includes the selection filters, ordering, paging and fields information.
It is serialized over the wire protocol and passed between the client and the server
func NewGetQuery ¶
NewGetQuery creates a new GetQuery for the given table, with all the other prams. The query can be used in a building sequence to add more parameters to it
func (*GetQuery) Filter ¶
Filter adds a WHERE filter to the query. returns the query itself so it can be used in a building sequence.
func (*GetQuery) FilterBetween ¶
func (*GetQuery) Limit ¶
Limit sets a limit for the number of results to get, assuming the offset is the first result. Use Page(offset, limit) for paging beyond the first resutls.
returns the query itself so it can be used in a building sequence.
func (GetQuery) Load ¶
Load executes the query on the client c, and maps the returning results to a model object(s).
If you pass a pointer to a slice of objects, this slice will be filled with objects of this type.
If you pass a pointer to a single object, the result will be mapped to this object only. Note that if there are more than 1 results and you pass a single object, Load will return an error.
If the query hasn't succeeded we return its error. If there were no results but no error, the slice will be of size 0, and a given object will remain unchanged
func (*GetQuery) OrderBy ¶
OrderBy adds ordering information to the query's selection. If it is missing, We order by the index this query is based on. Both lexical and numeric ordering are supported (floats, ints or timestamps)
If an ordering directive is present, it must be either the sole property selection index, or the last property of it.
i.e. if you have a in index on (name, birth_date) you can order by birth_date only. This requires careful planning of the indexes :)
We do not allow unindexed ordering. If the order parameter is not the last or sole property of the seleciton index, the query fails
type GetResponse ¶
type GetResponse struct { *Response Entities []schema.Entity `bson:"entities"` // the total number of entities matching this response, regardless of how many entities we've retrived Total int `bson:"total"` }
func NewGetResponse ¶
func NewGetResponse(err error) *GetResponse
func NewGetResponseSize ¶
func NewGetResponseSize(err error, sizeHint int) *GetResponse
func (*GetResponse) AddEntity ¶
func (r *GetResponse) AddEntity(e schema.Entity)
func (GetResponse) MapEntities ¶
func (r GetResponse) MapEntities(dst interface{}) error
type Ordering ¶
type PingResponse ¶
type PingResponse struct {
*Response
}
func NewPingResponse ¶
func NewPingResponse() PingResponse
type PutResponse ¶
func NewPutResponse ¶
func NewPutResponse(err error, ids ...schema.Key) *PutResponse
type Query ¶
type Query interface {
Validate() error
}
Query is just the commmon interface for all queries. They must validate themselves
type QueryResult ¶
type Response ¶
type Response struct { Time time.Duration `bson:"time"` Error *errors.Error `bson:"error"` // contains filtered or unexported fields }
func NewResponse ¶
type UpdateQuery ¶
type UpdateQuery struct { Table string `bson:"table"` Filters Filters `bson:"filters"` Changes []Change `bson:"changes"` }
UpdateQuery represents an UPDATE request sent to the server and processed by the relevant driver
func NewUpdateQuery ¶
func NewUpdateQuery(table string) *UpdateQuery
NewUpdateQuery initializes an update query for a given table
func (*UpdateQuery) DelProperty ¶
func (q *UpdateQuery) DelProperty(prop string) *UpdateQuery
DelProperty is an UPDATE change that deletes a single property from an entity
func (*UpdateQuery) Expire ¶
func (q *UpdateQuery) Expire(ttl time.Duration) *UpdateQuery
func (*UpdateQuery) Increment ¶
func (q *UpdateQuery) Increment(prop string, newVal int64) *UpdateQuery
func (*UpdateQuery) Set ¶
func (q *UpdateQuery) Set(prop string, newVal interface{}) *UpdateQuery
Set adds a SET op change to the query's change set
func (*UpdateQuery) Validate ¶
func (q *UpdateQuery) Validate() (err error)
Validate tests the query's parameter for validity (not against a schema - just that they are sane). If any problem is found it returns an error
func (*UpdateQuery) Where ¶
func (q *UpdateQuery) Where(prop string, operator string, values ...interface{}) *UpdateQuery
Where adds a selection filter indicating what entities will be updated
func (*UpdateQuery) WhereEquals ¶
func (q *UpdateQuery) WhereEquals(prop string, values ...interface{}) *UpdateQuery
WhereEquals creates an Eq filter on the query
func (*UpdateQuery) WhereId ¶
func (q *UpdateQuery) WhereId(ids ...interface{}) *UpdateQuery
WhereId creates a selection filter by primary ids
type UpdateResponse ¶
UpdateResponse is used to send a response back to clients to an update query. It includes the usual Response fields, and the number of entities affected by the update
func NewUpdateResponse ¶
func NewUpdateResponse(err error, num int) *UpdateResponse
NewUpdateResponse creates a new response object to send back to a client, with a given error and the number of entities updated