Documentation
¶
Overview ¶
Package data provides a data structure for defining simple database filters. This is not able to represent every imaginable query criteria, but it does a good job of making common criteria simple to format and pass around in your application.
Index ¶
Constants ¶
const OperatorEqual = "="
OperatorEqual represents an "equals" comparison, when used in Predicates and Criteria
const OperatorGreaterOrEqual = ">="
OperatorGreaterOrEqual represents an "equals" comparison, when used in Predicates and Criteria
const OperatorGreaterThan = ">"
OperatorGreaterThan represents an "equals" comparison, when used in Predicates and Criteria
const OperatorLessOrEqual = "<="
OperatorLessOrEqual represents an "equals" comparison, when used in Predicates and Criteria
const OperatorLessThan = "<"
OperatorLessThan represents an "equals" comparison, when used in Predicates and Criteria
const OperatorNotEqual = "!="
OperatorNotEqual represents an "equals" comparison, when used in Predicates and Criteria
const OptionSortDirectionAscending = "ASC"
OptionSortDirectionAscending is the token that designates that records should be sorted lowest to highest
const OptionSortDirectionDescending = "DESC"
OptionSortDirectionDescending is the token that designates that records should be sorted highest to lowest
const OptionTypeMaxRows = "MAXROWS"
OptionTypeMaxRows is the token that designates the maximum number of records to be returned
const OptionTypeSort = "SORT"
OptionTypeSort is the token that designates a Sort order
const OptionTypeStartRow = "STARTROW"
OptionTypeStartRow is the token that designates the "row number" to begin results.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Datastore ¶
Datastore is an abstract representation of a database and its connection information.
type Expression ¶
type Expression []struct {
Name string // The name of the field being compared
Operator string // The type of comparison (=, !=, >, >=, <, <=). If this value is empty string, it is assumed to be "="
Value interface{} // The value that the field is being compared to
}
Expression represents a comparison or filter, to be used when loading objects from the database. Each service and database driver is expected to use this common format for query criteria, and then map it into the specific format required for that database.
func NewExpression ¶ added in v0.2.7
func NewExpression() *Expression
NewExpression returns a fully populated Expression
func (*Expression) Add ¶
func (exp *Expression) Add(name string, operator string, value interface{}) *Expression
Add appends a new predicate to an existing criteria expression.
func (Expression) Join ¶
func (exp Expression) Join(criteriaToCombine ...Expression) Expression
Join merges together the predicates of all provided criteria expressions, into a single criteria expression.
func (Expression) Match ¶
func (exp Expression) Match(object interface{}) bool
Match uses reflection to compare this expression with an arbitrary struct. It is included here to simplify testing and development, but should not be used for production-ready code.
type Iterator ¶ added in v0.2.5
Iterator interface allows callers to iterator over a large number of items in an array/slice
type Object ¶
type Object interface {
// ID returns the primary key of the object
ID() string
// IsNew returns TRUE if the object has not yet been saved to the database
IsNew() bool
// SetCreated stamps the CreateDate and UpdateDate of the object, and makes a note
SetCreated(comment string)
// SetUpdated stamps the UpdateDate of the object, and makes a note
SetUpdated(comment string)
// SetDeleted marks the object virtually "deleted", and makes a note
SetDeleted(comment string)
}
Object interface defines all of the methods that a Domain Object must provide to Presto
type Option ¶ added in v0.2.7
Option is a value that modifies a READ query result
func OptionMaxRows ¶ added in v0.2.7
OptionMaxRows returns a query option that will limit the query results to a certain number of rows
func OptionSortAsc ¶ added in v0.2.7
OptionSortAsc returns a query option that will sort the query results in ASCENDING order
func OptionSortDesc ¶ added in v0.2.7
OptionSortDesc returns a query option that will sort the query results in DESCENDING order
func OptionStartRow ¶ added in v0.2.7
OptionStartRow returns a query option that will limit the query results to a certain number of rows
type Predicate ¶
type Predicate struct {
Name string // The name of the field being compared
Operator string // The type of comparison (=, !=, >, >=, <, <=). If this value is empty string, it is assumed to be "="
Value interface{} // The value that the field is being compared to
}
Predicate represents a single expression, such as [name = "John Connor"]
type Session ¶
type Session interface {
List(collection string, filter Expression, sort []string) (Iterator, *derp.Error)
Load(collection string, filter Expression, target Object) *derp.Error
Save(collection string, object Object, note string) *derp.Error
Delete(collection string, object Object, note string) *derp.Error
Close()
}
Session represents a single database session, that is opened to support a single transactional request, and then closed when this transaction is complete