Documentation
¶
Index ¶
- Variables
- func Columns(doc bsonkit.Doc) ([]bsonkit.Column, error)
- func Distinct(list bsonkit.List, path string) bson.A
- func Extract(query bsonkit.Doc) (bsonkit.Doc, error)
- func Filter(list bsonkit.List, query bsonkit.Doc, limit int) (bsonkit.List, error)
- func Match(doc, query bsonkit.Doc) (bool, error)
- func Process(ctx Context, doc bsonkit.Doc, query bson.D, prefix string, root bool) error
- func ProcessExpression(ctx Context, doc bsonkit.Doc, prefix string, pair bson.E, root bool) error
- func Project(doc, projection bsonkit.Doc) (bsonkit.Doc, error)
- func ProjectList(list bsonkit.List, projection bsonkit.Doc) (bsonkit.List, error)
- func Resolve(path string, query, doc bsonkit.Doc, arrayFilters bsonkit.List, ...) error
- func Sort(list bsonkit.List, doc bsonkit.Doc) (bsonkit.List, error)
- func SplitDynamicPath(path string) (string, string, string)
- type Changes
- type Collection
- func (c *Collection) Clone() *Collection
- func (c *Collection) CreateIndex(name string, config IndexConfig) (string, error)
- func (c *Collection) Delete(query, sort bsonkit.Doc, skip, limit int) (*Result, error)
- func (c *Collection) DropIndex(name string) ([]string, error)
- func (c *Collection) Find(query, sort bsonkit.Doc, skip, limit int) (*Result, error)
- func (c *Collection) Insert(doc bsonkit.Doc) (*Result, error)
- func (c *Collection) Replace(query, repl, sort bsonkit.Doc) (*Result, error)
- func (c *Collection) Update(query, update, sort bsonkit.Doc, skip, limit int, arrayFilters bsonkit.List) (*Result, error)
- func (c *Collection) Upsert(query, repl, update bsonkit.Doc, arrayFilters bsonkit.List) (*Result, error)
- type Context
- type Index
- func (i *Index) Add(doc bsonkit.Doc) (bool, error)
- func (i *Index) Build(list bsonkit.List) (bool, error)
- func (i *Index) Clone() *Index
- func (i *Index) Config() IndexConfig
- func (i *Index) Has(doc bsonkit.Doc) (bool, error)
- func (i *Index) List() bsonkit.List
- func (i *Index) Remove(doc bsonkit.Doc) (bool, error)
- type IndexConfig
- type Operator
- type Result
Constants ¶
This section is empty.
Variables ¶
var ErrNotMatched = errors.New("not matched")
ErrNotMatched is returned by query operators if the document does not match.
var ExpressionExtractOperators = map[string]Operator{}
ExpressionExtractOperators defines the expression extract operators.
var ExpressionQueryOperators = map[string]Operator{}
ExpressionQueryOperators defines the expression query operators.
var FieldUpdateOperators = map[string]Operator{}
FieldUpdateOperators defines the field update operators.
var ProjectionExpressionOperators = map[string]Operator{}
ProjectionExpressionOperators defines the available projection operators.
var TopLevelExtractOperators = map[string]Operator{}
TopLevelExtractOperators defines the top level extract operators.
var TopLevelQueryOperators = map[string]Operator{}
TopLevelQueryOperators defines the top level query operators
Functions ¶
func Distinct ¶
Distinct will perform a MongoDB distinct value search on the list of documents and return an array with the results.
func Extract ¶
Extract will extract the constant parts of a MongoDB query. The returned document may be used as the basis of an upsert operation.
func Filter ¶
Filter will filter a list of documents based on the specified MongoDB query document. A limit may be set to return early then the list is full.
func Process ¶
Process will process a document with a query using the MongoDB operator processing algorithm.
func ProcessExpression ¶
ProcessExpression will process a document with a query using the MongoDB operator algorithm.
func Project ¶
Project will apply the specified project to the document and return the resulting document.
func ProjectList ¶
ProjectList will apply the provided projection to the specified list.
func Resolve ¶ added in v0.2.0
func Resolve(path string, query, doc bsonkit.Doc, arrayFilters bsonkit.List, callback func(path string) error) error
Resolve will resolve all positional operators in the provided path using the query, document and array filters. For each match it will call the callback with the generated absolute path.
func Sort ¶
Sort will sort a list based on a MongoDB sort document and return a new list with sorted documents.
func SplitDynamicPath ¶ added in v0.2.0
SplitDynamicPath will split the provided path on the first positional operator. It will return the leading path, the operator and the trailing path. The segments may be set to bsonkit.PathEnd if there are not available in the path.
Types ¶
type Changes ¶
type Changes struct { // Whether the operation was an upsert. Upsert bool // The fields that have been added, updated or removed in the document. // Added and updated fields are set to the final value while removed fields // are set to bsonkit.Missing. Changed map[string]interface{} // contains filtered or unexported fields }
Changes record the applied changes to a document.
func Apply ¶
func Apply(doc, query, update bsonkit.Doc, upsert bool, arrayFilters bsonkit.List) (*Changes, error)
Apply will apply a MongoDB update document on a document using the various update operators. The document is updated in place. The changes to the document are recorded and returned.
type Collection ¶
Collection combines a set and multiple indexes to form a basic MongoDB like collection that offers basic CRUD capabilities. The collection is not safe from concurrent access and does not roll back changes on errors. Therefore, the recommended approach is to clone the collection before making changes.
func NewCollection ¶
func NewCollection(idIndex bool) *Collection
NewCollection will create and return a new collection.
func (*Collection) Clone ¶
func (c *Collection) Clone() *Collection
Clone will clone the collection.
func (*Collection) CreateIndex ¶
func (c *Collection) CreateIndex(name string, config IndexConfig) (string, error)
CreateIndex will create and build an index based on the specified configuration. If the index name is missing, it will be generated from the config and returned.
func (*Collection) DropIndex ¶
func (c *Collection) DropIndex(name string) ([]string, error)
DropIndex will drop the specific index or drop all indexes if no name has been specified.
func (*Collection) Insert ¶
func (c *Collection) Insert(doc bsonkit.Doc) (*Result, error)
Insert will add the specified document to the collection.
func (*Collection) Replace ¶
func (c *Collection) Replace(query, repl, sort bsonkit.Doc) (*Result, error)
Replace will look up the first document that matches the query and if found replace it with the specified document.
type Context ¶
type Context struct { // The available top level operators. TopLevel map[string]Operator // The available expression operators. Expression map[string]Operator // Whether missing operators should just be skipped. SkipMissing bool // If enabled, top level operators will expect a document with multiple // invocations of the operator. MultiTopLevel bool // A custom value available to the operators. Value interface{} // The query used to resolve positional operators in top level operator // invocation paths. TopLevelQuery bsonkit.Doc // The array filters used to resolve positional operators in top level // operator invocation paths. TopLevelArrayFilters bsonkit.List }
Context is the context passed to operators.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is an index for documents that supports MongoDB features. The index is not safe from concurrent access and does not roll back changes on errors. Therefore, the recommended approach is to clone the index before making changes.
func CreateIndex ¶
func CreateIndex(config IndexConfig) (*Index, error)
CreateIndex will create and return a new index.
func (*Index) Add ¶
Add will add the document to index. May return false if the document has already been added to the index. If the document has been skipped due to a partial filter true is returned.
func (*Index) Build ¶
Build will build the index from the specified list. It may return false if there was a unique constraint error when building the index.
func (*Index) Clone ¶
Clone will clone the index. Mutating the new index will not mutate the original index.
func (*Index) Config ¶
func (i *Index) Config() IndexConfig
Config will return the index configuration.
type IndexConfig ¶
type IndexConfig struct { // The index key. Key bsonkit.Doc // Whether the index is unique. Unique bool // The partial index filter. Partial bsonkit.Doc // The time after documents expire. Expiry time.Duration }
IndexConfig defines an index configuration.
func (IndexConfig) Equal ¶ added in v0.1.2
func (c IndexConfig) Equal(d IndexConfig) bool
Equal will compare to configurations and return whether they are equal.
func (IndexConfig) Name ¶ added in v0.1.2
func (c IndexConfig) Name() (string, error)
Name will return the computed index name.
type Result ¶
type Result struct { // The list of found or deleted documents. Matched bsonkit.List // The list of inserted, replaced or updated documents. Modified bsonkit.List // The upserted document. Upserted bsonkit.Doc // The changes applied to updated documents. Changes []*Changes }
Result is returned by collection operations.