Documentation ¶
Index ¶
- Constants
- Variables
- func CompareValues(v1, v2 Value) int
- func Register(reg Registration)
- func ValuesEqual(v1, v2 Value) bool
- type BatchInserter
- type Bool
- type Bytes
- type Database
- type Delete
- type DocIterator
- type DocWriter
- type Document
- type FieldFilter
- type FilterOp
- type Float
- type Index
- type IndexType
- type Int
- type Key
- type OpenFunc
- type Options
- type Query
- type Registration
- type String
- type Strings
- type Time
- type Traits
- type Update
- type Value
Constants ¶
const ( Equal = FilterOp(iota + 1) NotEqual GT GTE LT LTE Regexp )
const ( IndexAny = IndexType(iota) StringExact // exact match for string values (usually a hash index) )
Variables ¶
var ErrNotFound = errors.New("not found")
Functions ¶
func CompareValues ¶
CompareValues return 0 if values are equal, positive value if first value sorts after second, and negative otherwise.
func ValuesEqual ¶
ValuesEqual returns true if values are strictly equal.
Types ¶
type BatchInserter ¶
BatchInserter is an optional interface for databases that can insert documents in batches.
type Bytes ¶
type Bytes []byte
Bytes is a raw binary data.
Some databases has no type to represent binary data. In this case base64 representation can be used and package will take care of converting it.
type Database ¶
type Database interface { // Insert creates a document with a given key in a given collection. // Key can be nil meaning that implementation should generate a unique key for the item. // It returns the key that was generated, or the same key that was passed to it. Insert(ctx context.Context, col string, key Key, d Document) (Key, error) // FindByKey finds a document by it's Key. It returns ErrNotFound if document not exists. FindByKey(ctx context.Context, col string, key Key) (Document, error) // Query starts construction of a new query for a specified collection. Query(col string) Query // Update starts construction of document update request for a specified document and collection. Update(col string, key Key) Update // Delete starts construction of document delete request. Delete(col string) Delete // EnsureIndex creates or updates indexes on the collection to match it's arguments. // It should create collection if it not exists. Primary index is guaranteed to be of StringExact type. EnsureIndex(ctx context.Context, col string, primary Index, secondary []Index) error // Close closes the database connection. Close() error }
Database is a minimal interface for NoSQL database implementations.
type Delete ¶
type Delete interface { // WithFields adds specified filters to select document for deletion. WithFields(filters ...FieldFilter) Delete // Keys limits a set of documents to delete to ones with keys specified. // Delete still uses provided filters, thus it will not delete objects with these keys if they do not pass filters. Keys(keys ...Key) Delete // Do executes batch delete. Do(ctx context.Context) error }
Update is a batch delete request builder.
type DocIterator ¶
type DocIterator interface { // Next advances an iterator to the next document. Next(ctx context.Context) bool // Err returns a last encountered error. Err() error // Close frees all resources associated with iterator. Close() error // Key returns a key of current document. Key() Key // Doc returns current document. Doc() Document }
DocIterator is an iterator over a list of documents.
type DocWriter ¶
type DocWriter interface { // WriteDoc prepares document to be written. Write becomes valid only after Flush. WriteDoc(ctx context.Context, key Key, d Document) error // Flush waits for all writes to complete. Flush(ctx context.Context) error // Keys returns a list of already inserted documents. // Might be less then a number of written documents until Flush is called. Keys() []Key // Close closes writer and discards any unflushed documents. Close() error }
DocWriter is an interface for writing documents in streaming manner.
func BatchInsert ¶
BatchInsert returns a streaming writer for database or emulates it if database has no support for batch inserts.
type FieldFilter ¶
type FieldFilter struct { Path []string // path is a path to specific field in the document Filter FilterOp // comparison operation Value Value // value that will be compared with field of the document }
FieldFilter represents a single field comparison operation.
func (FieldFilter) Matches ¶
func (f FieldFilter) Matches(doc Document) bool
type Float ¶
type Float float64
Float is an floating point value.
Some databases might not distinguish Int value from Float. In this case the package will take care of converting it to a correct type.
type Int ¶
type Int int64
Int is an int value.
Some databases might not distinguish Int value from Float. In this case implementation will take care of converting it to a correct type.
type Key ¶
type Key []string
Key is a set of values that describe primary key of document.
type OpenFunc ¶
OpenFunc is a function for opening a database given a address and the database name.
type Query ¶
type Query interface { // WithFields adds specified filters to the query. WithFields(filters ...FieldFilter) Query // Limit limits a maximal number of results returned. Limit(n int) Query // Count executes query and returns a number of items that matches it. Count(ctx context.Context) (int64, error) // One executes query and returns first document from it. One(ctx context.Context) (Document, error) // Iterate starts an iteration over query results. Iterate(ctx context.Context) DocIterator }
Query is a query builder object.
type Registration ¶
type Registration struct { base.Registration New, Open OpenFunc Traits Traits }
Registration is an information about the database driver.
func ByName ¶
func ByName(name string) *Registration
ByName returns a registered database driver by it's name.
type Time ¶
Time is a timestamp value.
Some databases has no type to represent time values. In this case string/json representation can be used and package will take care of converting it.
type Update ¶
type Update interface { // Inc increments document field with a given amount. Will also increment upserted document. Inc(field string, dn int) Update // Upsert sets a document that will be inserted in case original object does not exists already. // It should omit fields used by Inc - they will be added automatically. Upsert(d Document) Update // Do executes update request. Do(ctx context.Context) error }
Update is an update request builder.