Documentation ¶
Index ¶
- Constants
- Variables
- func CompareValues(v1, v2 Value) int
- func Init(db Database, opt graph.Options) error
- func Register(name string, r 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 InitFunc
- type Int
- type Iterator
- func (it *Iterator) Clone() graph.Iterator
- func (it *Iterator) Close() error
- func (it *Iterator) Contains(ctx context.Context, v graph.Value) bool
- func (it *Iterator) Err() error
- func (it *Iterator) Next(ctx context.Context) bool
- func (it *Iterator) NextPath(ctx context.Context) bool
- func (it *Iterator) Optimize() (graph.Iterator, bool)
- func (it *Iterator) Reset()
- func (it *Iterator) Result() graph.Value
- func (it *Iterator) Size() (int64, bool)
- func (it *Iterator) Sorted() bool
- func (it *Iterator) Stats() graph.IteratorStats
- func (it *Iterator) String() string
- func (it *Iterator) SubIterators() []graph.Iterator
- func (it *Iterator) TagResults(dst map[string]graph.Value)
- func (it *Iterator) Tagger() *graph.Tagger
- func (it *Iterator) Type() graph.Type
- func (it *Iterator) UID() uint64
- type Key
- type Linkage
- type NewFunc
- type NodeHash
- type Options
- type QuadHash
- type QuadStore
- func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreOpts graph.IgnoreOpts) error
- func (qs *QuadStore) Close() error
- func (qs *QuadStore) NameOf(v graph.Value) quad.Value
- func (qs *QuadStore) NodesAllIterator() graph.Iterator
- func (qs *QuadStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool)
- func (qs *QuadStore) OptimizeShape(s shape.Shape) (shape.Shape, bool)
- func (qs *QuadStore) Quad(val graph.Value) quad.Quad
- func (qs *QuadStore) QuadDirection(in graph.Value, d quad.Direction) graph.Value
- func (qs *QuadStore) QuadIterator(d quad.Direction, val graph.Value) graph.Iterator
- func (qs *QuadStore) QuadsAllIterator() graph.Iterator
- func (qs *QuadStore) Size() int64
- func (qs *QuadStore) ValueOf(s quad.Value) graph.Value
- type Quads
- type Query
- type Registration
- type Shape
- type String
- type Strings
- type Time
- 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) )
const DefaultDBName = "cayley"
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 Register ¶
func Register(name string, r Registration)
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(d 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 Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
func NewAllIterator ¶
func NewIterator ¶
func NewIterator(qs *QuadStore, collection string, constraints ...FieldFilter) *Iterator
func NewLinksToIterator ¶
func (*Iterator) Stats ¶
func (it *Iterator) Stats() graph.IteratorStats
func (*Iterator) SubIterators ¶
type Key ¶
type Key []string
Key is a set of values that describe primary key of document.
type Options ¶ added in v0.7.1
type Options struct {
Number32 bool // store is limited to 32 bit precision
}
type QuadStore ¶
type QuadStore struct {
// contains filtered or unexported fields
}
func NewQuadStore ¶ added in v0.7.1
func (*QuadStore) ApplyDeltas ¶
func (*QuadStore) NodesAllIterator ¶
func (*QuadStore) OptimizeIterator ¶
func (*QuadStore) OptimizeShape ¶
func (*QuadStore) QuadDirection ¶
func (*QuadStore) QuadIterator ¶
func (*QuadStore) QuadsAllIterator ¶
type Quads ¶
type Quads struct { Links []Linkage // filters to select quads Limit int64 // limits a number of documents }
Quads is a shape representing a quads query
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() DocIterator }
Query is a query builder object.
type Registration ¶
type Shape ¶
type Shape struct { Collection string // name of the collection Filters []FieldFilter // filters to select documents Limit int64 // limits a number of documents }
Shape is a shape representing a documents query with filters
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.