query

package
v2.0.0-alpha.4-fix Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExistsOp = iota
	EqOp
	NeqOp
	GtOp
	GtEqOp
	LtOp
	LtEqOp
	LikeOp
	InOp
	ContainsOp
	FunctionOp
)
View Source
const (
	LogicalAnd = iota
	LogicalOr
)

Variables

This section is empty.

Functions

func Field

func Field(name string) *field

Field represents a document field. It is used to create a new criteria.

func IsField

func IsField(v interface{}) bool

Types

type BinaryCriteria

type BinaryCriteria struct {
	OpType int
	C1, C2 Criteria
}

func (*BinaryCriteria) Accept

func (c *BinaryCriteria) Accept(v CriteriaVisitor) interface{}

func (*BinaryCriteria) And

func (c *BinaryCriteria) And(other Criteria) Criteria

func (*BinaryCriteria) Not

func (c *BinaryCriteria) Not() Criteria

func (*BinaryCriteria) Or

func (c *BinaryCriteria) Or(other Criteria) Criteria

func (*BinaryCriteria) Satisfy

func (c *BinaryCriteria) Satisfy(doc *d.Document) bool

type Criteria

type Criteria interface {
	Satisfy(doc *d.Document) bool
	Accept(v CriteriaVisitor) interface{}
	Not() Criteria
	And(c Criteria) Criteria
	Or(c Criteria) Criteria
}

Criteria represents a predicate for selecting documents. It follows a fluent API style so that you can easily chain together multiple criteria.

type CriteriaVisitor

type CriteriaVisitor interface {
	VisitUnaryCriteria(c *UnaryCriteria) interface{}
	VisitNotCriteria(c *NotCriteria) interface{}
	VisitBinaryCriteria(c *BinaryCriteria) interface{}
}

type NotCriteria

type NotCriteria struct {
	C Criteria
}

func (*NotCriteria) Accept

func (c *NotCriteria) Accept(v CriteriaVisitor) interface{}

func (*NotCriteria) And

func (c *NotCriteria) And(other Criteria) Criteria

func (*NotCriteria) Not

func (c *NotCriteria) Not() Criteria

func (*NotCriteria) Or

func (c *NotCriteria) Or(other Criteria) Criteria

func (*NotCriteria) Satisfy

func (c *NotCriteria) Satisfy(doc *d.Document) bool

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query represents a generic query which is submitted to a specific collection.

func NewQuery

func NewQuery(collection string) *Query

NewQuery simply returns the collection with the supplied name. Use it to initialize a new query.

func (*Query) Collection

func (q *Query) Collection() string

func (*Query) Criteria

func (q *Query) Criteria() Criteria

func (*Query) GetLimit

func (q *Query) GetLimit() int

func (*Query) GetSkip

func (q *Query) GetSkip() int

func (*Query) Limit

func (q *Query) Limit(n int) *Query

Limit sets the query q to consider at most n records. As a consequence, the FindAll() method will output at most n documents, and any integer m returned by Count() will satisfy the condition m <= n.

func (*Query) MatchFunc

func (q *Query) MatchFunc(p func(doc *d.Document) bool) *Query

MatchFunc selects all the documents which satisfy the supplied predicate function.

func (*Query) Skip

func (q *Query) Skip(n int) *Query

Skip sets the query so that the first n documents of the result set are discarded.

func (*Query) Sort

func (q *Query) Sort(opts ...SortOption) *Query

Sort sets the query so that the returned documents are sorted according list of options.

func (*Query) SortOptions

func (q *Query) SortOptions() []SortOption

func (*Query) Where

func (q *Query) Where(c Criteria) *Query

Where returns a new Query which select all the documents fulfilling the provided Criteria.

type SortOption

type SortOption struct {
	Field     string
	Direction int
}

SortOption is used to specify sorting options to the Sort method. It consists of a field name and a sorting direction (1 for ascending and -1 for descending). Any other positive of negative value (except from 1 and -1) will be equivalent, respectively, to 1 or -1. A direction value of 0 (which is also the default value) is assumed to be ascending.

type UnaryCriteria

type UnaryCriteria struct {
	OpType int
	Field  string
	Value  interface{}
}

func (*UnaryCriteria) Accept

func (c *UnaryCriteria) Accept(v CriteriaVisitor) interface{}

func (*UnaryCriteria) And

func (c *UnaryCriteria) And(other Criteria) Criteria

func (*UnaryCriteria) Not

func (c *UnaryCriteria) Not() Criteria

func (*UnaryCriteria) Or

func (c *UnaryCriteria) Or(other Criteria) Criteria

func (*UnaryCriteria) Satisfy

func (c *UnaryCriteria) Satisfy(doc *d.Document) bool

Jump to

Keyboard shortcuts

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