nosql

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Equal = FilterOp(iota + 1)
	NotEqual
	GT
	GTE
	LT
	LTE
	Regexp
)
View Source
const (
	IndexAny    = IndexType(iota)
	StringExact // exact match for string values (usually a hash index)

)
View Source
const DefaultDBName = "cayley"

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func CompareValues

func CompareValues(v1, v2 Value) int

CompareValues return 0 if values are equal, positive value if first value sorts after second, and negative otherwise.

func Init

func Init(db Database, opt graph.Options) error

func Register

func Register(name string, r Registration)

func ValuesEqual

func ValuesEqual(v1, v2 Value) bool

ValuesEqual returns true if values are strictly equal.

Types

type BatchInserter

type BatchInserter interface {
	BatchInsert(col string) DocWriter
}

BatchInserter is an optional interface for databases that can insert documents in batches.

type Bool

type Bool bool

Bool is a boolean value.

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

func BatchInsert(db Database, col string) DocWriter

BatchInsert returns a streaming writer for database or emulates it if database has no support for batch inserts.

type Document

type Document map[string]Value

Document is a type of item stored in nosql database.

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 FilterOp

type FilterOp int

FilterOp is a comparison operation type used for value filters.

func (FilterOp) GoString

func (op FilterOp) GoString() string

func (FilterOp) String

func (op FilterOp) String() string

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 Index

type Index struct {
	Fields []string // an ordered set of fields used in index
	Type   IndexType
}

Index is an index for a collection of documents.

type IndexType

type IndexType int

IndexType is a type of index for collection.

type InitFunc

type InitFunc func(string, graph.Options) (Database, error)

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 NewAllIterator(qs *QuadStore, collection string) *Iterator

func NewIterator

func NewIterator(qs *QuadStore, collection string, constraints ...FieldFilter) *Iterator

func NewLinksToIterator

func NewLinksToIterator(qs *QuadStore, collection string, links []Linkage) *Iterator

func (*Iterator) Clone

func (it *Iterator) Clone() graph.Iterator

func (*Iterator) Close

func (it *Iterator) Close() error

func (*Iterator) Contains

func (it *Iterator) Contains(ctx context.Context, v graph.Value) bool

func (*Iterator) Err

func (it *Iterator) Err() error

func (*Iterator) Next

func (it *Iterator) Next(ctx context.Context) bool

func (*Iterator) NextPath

func (it *Iterator) NextPath(ctx context.Context) bool

func (*Iterator) Optimize

func (it *Iterator) Optimize() (graph.Iterator, bool)

func (*Iterator) Reset

func (it *Iterator) Reset()

func (*Iterator) Result

func (it *Iterator) Result() graph.Value

func (*Iterator) Size

func (it *Iterator) Size() (int64, bool)

func (*Iterator) Sorted

func (it *Iterator) Sorted() bool

func (*Iterator) Stats

func (it *Iterator) Stats() graph.IteratorStats

func (*Iterator) String

func (it *Iterator) String() string

func (*Iterator) SubIterators

func (it *Iterator) SubIterators() []graph.Iterator

func (*Iterator) TagResults

func (it *Iterator) TagResults(dst map[string]graph.Value)

func (*Iterator) Tagger

func (it *Iterator) Tagger() *graph.Tagger

func (*Iterator) Type

func (it *Iterator) Type() graph.Type

func (*Iterator) UID

func (it *Iterator) UID() uint64

type Key

type Key []string

Key is a set of values that describe primary key of document.

func GenKey

func GenKey() Key

GenKey generates a unique key (with one field).

func KeyFrom

func KeyFrom(fields []string, doc Document) Key

KeyFrom extracts a set of fields as a Key from Document.

func (Key) Value

func (k Key) Value() Value

Value converts a Key to a value that can be stored in the database.

type Linkage

type Linkage struct {
	Dir quad.Direction
	Val NodeHash
}

type NewFunc

type NewFunc func(string, graph.Options) (Database, error)

type NodeHash

type NodeHash string

func (NodeHash) IsNode

func (NodeHash) IsNode() bool

func (NodeHash) Key

func (v NodeHash) Key() interface{}

type Options added in v0.7.1

type Options struct {
	Number32 bool // store is limited to 32 bit precision
}

type QuadHash

type QuadHash [4]string

func (QuadHash) Get

func (h QuadHash) Get(d quad.Direction) string

func (QuadHash) IsNode

func (QuadHash) IsNode() bool

func (QuadHash) Key

func (v QuadHash) Key() interface{}

type QuadStore

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

func NewQuadStore added in v0.7.1

func NewQuadStore(db Database, nopt *Options, opt graph.Options) (*QuadStore, error)

func (*QuadStore) ApplyDeltas

func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreOpts graph.IgnoreOpts) error

func (*QuadStore) Close

func (qs *QuadStore) Close() error

func (*QuadStore) NameOf

func (qs *QuadStore) NameOf(v graph.Value) quad.Value

func (*QuadStore) NodesAllIterator

func (qs *QuadStore) NodesAllIterator() graph.Iterator

func (*QuadStore) OptimizeIterator

func (qs *QuadStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool)

func (*QuadStore) OptimizeShape

func (qs *QuadStore) OptimizeShape(s shape.Shape) (shape.Shape, bool)

func (*QuadStore) Quad

func (qs *QuadStore) Quad(val graph.Value) quad.Quad

func (*QuadStore) QuadDirection

func (qs *QuadStore) QuadDirection(in graph.Value, d quad.Direction) graph.Value

func (*QuadStore) QuadIterator

func (qs *QuadStore) QuadIterator(d quad.Direction, val graph.Value) graph.Iterator

func (*QuadStore) QuadsAllIterator

func (qs *QuadStore) QuadsAllIterator() graph.Iterator

func (*QuadStore) Size

func (qs *QuadStore) Size() int64

func (*QuadStore) ValueOf

func (qs *QuadStore) ValueOf(s quad.Value) graph.Value

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

func (Quads) BuildIterator

func (s Quads) BuildIterator(qs graph.QuadStore) graph.Iterator

func (Quads) Optimize

func (s Quads) Optimize(r shape.Optimizer) (shape.Shape, bool)

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 Registration struct {
	NewFunc      NewFunc
	InitFunc     InitFunc
	IsPersistent bool
	Options
}

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

func (Shape) BuildIterator

func (s Shape) BuildIterator(qs graph.QuadStore) graph.Iterator

func (Shape) Optimize

func (s Shape) Optimize(r shape.Optimizer) (shape.Shape, bool)

type String

type String string

String is an UTF8 string value.

type Strings

type Strings []string

Strings is an array of strings. Used mostly to store Keys.

type Time

type Time time.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.

type Value

type Value interface {
	// contains filtered or unexported methods
}

Value is a interface that limits a set of types that nosql database can handle.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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