query

package
v0.0.0-...-d65df50 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2016 License: BSD-2-Clause Imports: 8 Imported by: 7

Documentation

Index

Constants

View Source
const (
	In      = "IN"
	Eq      = "="
	Gt      = ">"
	Lt      = "<"
	Between = "><"
	All     = "ALL"
)

Variables

View Source
var DefaultPagingLimit = 100

This sets the deault limit for queries that don't have limit built into them

View Source
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

func DelProperty(prop string) Change

DelProperty is an UPDATE change that deletes a single property from an entity

func Expire

func Expire(ttl time.Duration) Change

func Increment

func Increment(prop string, amount int64) Change

Incement returns a new Incr change for a property with a given integer value

func IncrementFloat

func IncrementFloat(prop string, amount float64) Change

IncrementFloat returns a new Incr for a property with a given float value. Should be used only on float properties

func Set

func Set(prop string, newVal interface{}) Change

Set returns a new SetOp change for a property to given value

func (Change) Validate

func (c Change) Validate() error

Validate makes sure a change is sane - the op is supported , etc

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

type DelQuery struct {
	Table   string  `bson:"table"`
	Filters Filters `bson:"filters"`
}

DelQuery represents a DEL request handled by the appropriate driver

func NewDelQuery

func NewDelQuery(table string) *DelQuery

NewDelQuery creates a new query object for a given table

func (DelQuery) Validate

func (q DelQuery) Validate() error

Validate performs a sanity check on a DelQuery and its filters

func (*DelQuery) Where

func (q *DelQuery) Where(prop string, operator string, values ...interface{}) *DelQuery

Where adds a selection filter to the query to determine which entitie will be deleted. returns the query itself for use in builder-style syntax

type DelResponse

type DelResponse struct {
	*Response
	Num int `bson:"num"`
}

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"`
}

func Equals

func Equals(property string, value interface{}) Filter

func NewFilter

func NewFilter(field, operator string, values ...interface{}) Filter

NewFilter creates a new filter for a property with a given operator and comparison values

func Range

func Range(property string, min, max interface{}) Filter

func Within

func Within(property string, values ...interface{}) Filter

func (Filter) Validate

func (f Filter) Validate() error

Validate checks the filter for validity and returns an error if something is wrong with the filter

type Filters

type Filters map[string]Filter

Fitlers is an abstraction over a map of filters for queries

func NewFilters

func NewFilters(filters ...Filter) Filters

func (Filters) One

func (f Filters) One() (Filter, bool)

If the map is just one filter, we return it and true. otherwise a zero filter and false

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

func NewGetQuery(table string) *GetQuery

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) All

func (q *GetQuery) All() *GetQuery

func (*GetQuery) Fields

func (q *GetQuery) Fields(props ...string) *GetQuery

Limit the GET query to a set of specific fields

func (*GetQuery) Filter

func (q *GetQuery) Filter(prop, op string, values ...interface{}) *GetQuery

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 (q *GetQuery) FilterBetween(prop string, min, max interface{}) *GetQuery

func (*GetQuery) FilterEq

func (q *GetQuery) FilterEq(prop string, value interface{}) *GetQuery

func (*GetQuery) FilterIn

func (q *GetQuery) FilterIn(prop string, values ...interface{}) *GetQuery

func (*GetQuery) Limit

func (q *GetQuery) Limit(limit int) *GetQuery

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

func (q GetQuery) Load(c client.Client, dst interface{}) (int, error)

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

func (q *GetQuery) OrderBy(prop string, mode SortMode) *GetQuery

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

func (*GetQuery) Page

func (q *GetQuery) Page(offset, limit int) *GetQuery

Page sets the paging parameters for the query. returns the query itself so it can be used in a building sequence.

func (GetQuery) String

func (q GetQuery) String() string

String representation of a query in Json

func (GetQuery) Validate

func (q GetQuery) Validate() error

Validate makes sure the query's parameters and filters are sane

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 Ordering struct {
	By        string `bson:"by"`
	Ascending bool   `bson:"asc"`
}

func (Ordering) IsNil

func (o Ordering) IsNil() bool

IsNil tells us whether an Ordering object actually contains any ordering directive or is just empty

func (Ordering) Validate

func (o Ordering) Validate() error

type Paging

type Paging struct {
	Offset int `bson:"offset"`
	Limit  int `bson:"limit"`
}

func (Paging) Validate

func (p Paging) Validate() error

type PingQuery

type PingQuery struct{}

func (PingQuery) Validate

func (PingQuery) Validate() error

type PingResponse

type PingResponse struct {
	*Response
}

func NewPingResponse

func NewPingResponse() PingResponse

type PutQuery

type PutQuery struct {
	Table    string          `bson:"table"`
	Entities []schema.Entity `bson:"entities"`
}

func NewPutQuery

func NewPutQuery(table string) *PutQuery

func NewPutQuerySize

func NewPutQuerySize(table string, capacity int) *PutQuery

func (*PutQuery) AddEntity

func (q *PutQuery) AddEntity(e schema.Entity) *PutQuery

func (PutQuery) Validate

func (q PutQuery) Validate() error

type PutResponse

type PutResponse struct {
	*Response
	Ids []schema.Key `bson:"ids"`
}

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 QueryResult interface {
	Elapsed() time.Duration
	Err() error
}

type Response

type Response struct {
	Time time.Duration `bson:"time"`

	Error *errors.Error `bson:"error"`
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(err error) *Response

func (*Response) Done

func (r *Response) Done()

func (*Response) Elapsed

func (r *Response) Elapsed() time.Duration

func (*Response) Err

func (r *Response) Err() error

func (*Response) String

func (r *Response) String() string

type SortMode

type SortMode string
const (
	ASC  SortMode = "ASC"
	DESC SortMode = "DESC"
)

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

type UpdateResponse struct {
	*Response
	Num int `bson:"num"`
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL