Documentation ¶
Index ¶
- Constants
- Variables
- func Convert(criteria SearchCriteria, qh *QueryHandler) map[string]interface{}
- func GetOperatorPattern() *regexp.Regexp
- func GetRegexPattern() *regexp.Regexp
- func ParseValue(value string, qh *QueryHandler, cast *CastType) interface{}
- type CastType
- type FindOptions
- type Primitives
- type Query
- type QueryHandler
- type Regex
- type SearchCriteria
- type SearchOperator
- type Visitor
- func (v *Visitor) Visit(tree antlr.ParseTree) interface{}
- func (v *Visitor) VisitAtomQuery(ctx *parser.AtomQueryContext) interface{}
- func (v *Visitor) VisitCriteria(ctx *parser.CriteriaContext) interface{}
- func (v *Visitor) VisitInput(ctx *parser.InputContext) interface{}
- func (v *Visitor) VisitOpQuery(ctx *parser.OpQueryContext) interface{}
- func (v *Visitor) VisitPriorityQuery(ctx *parser.PriorityQueryContext) interface{}
Constants ¶
const DATE_FORMAT = "2006-01-02T15:04:05.000Z"
const OPERATOR_PATTERN string = "(?P<Prefix>!?)(?P<Key>[^><!=]+)(?P<Operator>[><]=?|!?=|)(?P<Value>.*)"
const REGEX_PATTERN string = "^\\/(?P<Pattern>.*)\\/(?P<Option>[igm]*)$"
Variables ¶
var ( // ErrUnescapeCharacters is returned when cannot converter an unescape string ErrUnescapeCharacters = errors.New("unescape characters") // ErrValueNoMatch is returned when the converter cannot match a string to // an unsigned integer. ErrValueNoMatch = errors.New("value does not match") // ErrQueryVisitor ErrQueryVisitor = errors.New("context does not exists") )
Functions ¶
func Convert ¶
func Convert(criteria SearchCriteria, qh *QueryHandler) map[string]interface{}
Convert converts the criteria value to a MongoDB query
func GetOperatorPattern ¶
GetOperatorPattern gets operator RegExp pattern
func ParseValue ¶
func ParseValue(value string, qh *QueryHandler, cast *CastType) interface{}
ParseValue converts a string to a data type
Types ¶
type FindOptions ¶
type FindOptions struct { // Caster map to set object type on values by key (BOOLEAN, NUMBER, PATTERN, DATE, STRING). Caster *map[string]CastType // DefaultLimit default value for limit key. DefaultLimit *int64 // MaxLimit maximum value for limit key. MaxLimit *int64 }
FindOptions is a structure that allows to use advanced options.
func (*FindOptions) SetCaster ¶
func (f *FindOptions) SetCaster(m map[string]CastType) *FindOptions
SetCaster sets the value for the object type on values by key.
func (*FindOptions) SetDefaultLimit ¶
func (f *FindOptions) SetDefaultLimit(i int64) *FindOptions
SetDefaultLimit sets the value for the default value for limit key.
func (*FindOptions) SetMaxLimit ¶
func (f *FindOptions) SetMaxLimit(i int64) *FindOptions
SetMaxLimit sets the value for the maximum value for limit key.
type Primitives ¶ added in v1.1.0
Primitives defines methods to convert to specific types.
type Query ¶
type Query struct { // Filter is a document containing query operators. Filter map[string][]interface{} // Sort is a document specifying the order in which documents should be returned. Sort map[string]int // Limit is the maximum number of documents to return. Limit int64 // Skip is a number of documents to be skipped. Skip int64 // Projection is the limit fields to return in each records. Projection map[string]int }
Query is a structure that holds information about DB request.
type QueryHandler ¶ added in v1.1.0
type QueryHandler struct {
Primitives Primitives
}
QueryHandler handles query construction for MongoDB.
func NewQueryHandler ¶ added in v1.1.0
func NewQueryHandler(primitives Primitives) *QueryHandler
NewQueryHandler creates a new QueryHandler instance.
func (*QueryHandler) MongoGoSearch ¶ added in v1.1.0
func (qh *QueryHandler) MongoGoSearch(query string, opts *FindOptions) (Query, error)
MongoGoSearch converts query into a MongoDB query object.
type Regex ¶
type Regex struct { // Pattern is a string contains regex pattern should be used. Pattern string // Opetion is a string contains regex options should be used. Option string }
Regex is a structure that holds RegExp specification.
type SearchCriteria ¶
type SearchCriteria struct { // Prefix is a bool that allows to check that the search criteria contain prefixes. Prefix bool // key is a string that allows the key to be identified in the search criteria. Key string // Operation is a structure that containing operator type. Operation SearchOperator // Value is a string that allows the value to be identified in the search criteria. Value string // Caster is a cast type value. Caster *CastType }
SearchCriteria is a structure that holds search criteria specification.
func CriteriaParser ¶ added in v1.0.1
func CriteriaParser(condition string, caster *map[string]CastType) SearchCriteria
CriteriaParser build criteria from a condition expression
type SearchOperator ¶
type SearchOperator int
const ( EQUAL SearchOperator = iota + 1 NOT_EQUAL GREATER_THAN GREATER_THAN_EQUAL LESS_THAN LESS_THAN_EQUAL EXISTS )
list of allowed operators.
func (SearchOperator) GetOperation ¶
func (s SearchOperator) GetOperation(input string) SearchOperator
GetOperation allows get operation type to filter query
type Visitor ¶ added in v1.0.1
type Visitor struct { *parser.BaseQueryVisitor QueryHandler *QueryHandler Caster *map[string]CastType }
func NewGeneratorVisitor ¶ added in v1.0.1
func NewGeneratorVisitor(qh *QueryHandler, caster *map[string]CastType) *Visitor
func (*Visitor) VisitAtomQuery ¶ added in v1.0.1
func (v *Visitor) VisitAtomQuery(ctx *parser.AtomQueryContext) interface{}
func (*Visitor) VisitCriteria ¶ added in v1.0.1
func (v *Visitor) VisitCriteria(ctx *parser.CriteriaContext) interface{}
func (*Visitor) VisitInput ¶ added in v1.0.1
func (v *Visitor) VisitInput(ctx *parser.InputContext) interface{}
func (*Visitor) VisitOpQuery ¶ added in v1.0.1
func (v *Visitor) VisitOpQuery(ctx *parser.OpQueryContext) interface{}
func (*Visitor) VisitPriorityQuery ¶ added in v1.0.1
func (v *Visitor) VisitPriorityQuery(ctx *parser.PriorityQueryContext) interface{}