Documentation ¶
Index ¶
- func RegisterStorageBackend(name string, factoryFunc func(path string) StorageBackend) error
- type And
- type Collection
- func (c *Collection) AddIndex(field string) error
- func (c *Collection) Delete(id Id) error
- func (c *Collection) Insert(value interface{}) (Id, error)
- func (c *Collection) Query(q Condition) (*Result, error)
- func (c *Collection) QueryAll() (*Result, error)
- func (c *Collection) QueryId(id Id) (*Result, error)
- func (c *Collection) Reindex(field string) error
- func (c *Collection) RemoveIndex(field string) error
- func (c *Collection) Update(id Id, value interface{}) error
- func (c *Collection) Vacuum() error
- type Condition
- type Database
- type DiskvStorageBackend
- type Equals
- type Id
- type LevelDBStorageBackend
- type Or
- type Result
- type StorageBackend
- type StorageType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterStorageBackend ¶
func RegisterStorageBackend(name string, factoryFunc func(path string) StorageBackend) error
RegisterStorageBackend registers a new custom storage backend under a new name. If the name is already used, an error is returned.
In order to create a new custom storage backend, the programmer must also provide a function that takes the path where the storage backend must write its data (as a single file or within a directory) and that returns an object that satisfies the interface StorageBackend
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
func (*Collection) AddIndex ¶
func (c *Collection) AddIndex(field string) error
AddIndex creates an index for a field. Existing records will be indexed, and future insert and update operations will index that field, as well. If an index for that field already exists, the AddIndex() is a no-op.
A field describes a top-level element of a struct or a particular key of a map.
func (*Collection) Delete ¶
func (c *Collection) Delete(id Id) error
Delete deletes an object, identified by its ID, from the collection.
func (*Collection) Insert ¶
func (c *Collection) Insert(value interface{}) (Id, error)
Insert inserts an object into the collection. It returns the object's ID and, if the insert fails, a non-nil error describing the problem.
func (*Collection) Query ¶
func (c *Collection) Query(q Condition) (*Result, error)
Query takes a query in the form of a (possibly nested) Condition, and returns a Result object.
func (*Collection) QueryAll ¶
func (c *Collection) QueryAll() (*Result, error)
QueryAll returns a Result object that will deliver all objects in the object store in no particular order.
func (*Collection) QueryId ¶
func (c *Collection) QueryId(id Id) (*Result, error)
QueryId returns a Result object that will exactly deliver the object with the requested ID.
func (*Collection) Reindex ¶
func (c *Collection) Reindex(field string) error
Reindex deletes and recreates the index for a field.
func (*Collection) RemoveIndex ¶
func (c *Collection) RemoveIndex(field string) error
RemoveIndex removes an existing index for a field. It returns a non-nil error if an error occurs.
func (*Collection) Update ¶
func (c *Collection) Update(id Id, value interface{}) error
Update replaces an existing object with a new object. If an error occurs during that operation, it returns a non-nil error.
func (*Collection) Vacuum ¶
func (c *Collection) Vacuum() error
Vacuum expunges old entries that refer to deleted objects from all indexes of a collection.
type Condition ¶
type Condition interface {
// contains filtered or unexported methods
}
func Expression ¶
Expression converts a S-Expr-based query to a structure of Condition objects. The following symbols are available for queries:
(id 1) query entry with ID 1 (eq field-name value) query all entries where field-name equals value (or expr...) OR all query sub-expressions (and expr...) AND all query sub-expressions
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func OpenDatabase ¶
func OpenDatabase(path string, typ StorageType) (*Database, error)
OpenDatabase opens and if necessary creates a database identified by the provided path. It returns a database object and a non-nil error if an error occured while opening or creating the database.
func (*Database) Close ¶
Close closes the database and frees the memory associated with all collections.
func (*Database) Coll ¶
func (db *Database) Coll(name string) *Collection
Coll returns the collection of the specified name. If the collection doesn't exist yet, it is opened and/or created on the fly.
func (*Database) Collections ¶
Collections returns a list of collection names that are currently in the database.
type DiskvStorageBackend ¶
type DiskvStorageBackend struct {
// contains filtered or unexported fields
}
func (*DiskvStorageBackend) Erase ¶
func (s *DiskvStorageBackend) Erase(key string) error
func (*DiskvStorageBackend) Keys ¶
func (s *DiskvStorageBackend) Keys() <-chan string
type LevelDBStorageBackend ¶
type LevelDBStorageBackend struct {
// contains filtered or unexported fields
}
func (*LevelDBStorageBackend) Erase ¶
func (s *LevelDBStorageBackend) Erase(key string) error
func (*LevelDBStorageBackend) Keys ¶
func (s *LevelDBStorageBackend) Keys() <-chan string
type StorageBackend ¶
type StorageBackend interface { Read(key string) ([]byte, error) Write(key string, value []byte) error Erase(key string) error Keys() <-chan string }
func NewDiskvStorageBackend ¶
func NewDiskvStorageBackend(path string) StorageBackend
func NewLevelDBStorageBackend ¶
func NewLevelDBStorageBackend(path string) StorageBackend
type StorageType ¶
type StorageType string
const ( STORAGE_AUTO StorageType = "auto" STORAGE_DISKV StorageType = "diskv" STORAGE_LEVELDB StorageType = "leveldb" )