db

package
v0.0.0-...-d0f4a43 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2013 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Overview

Document collection.

Collection management (Database is a collection of collections). Collection management functions may not be invoked concurrently.

Query processor for embedded and HTTP API V2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalQueryV2

func EvalQueryV2(q interface{}, src *Col, result *map[uint64]struct{}) (err error)

Main entrance to query processor - evaluate a query and put result into result map (as map keys).

func GetIn

func GetIn(doc interface{}, path []string) (ret []interface{})

Resolve the attribute(s) in the document structure along the given path.

func StrHash

func StrHash(thing interface{}) uint64

Return string hash code (algorithm inspired by Java String.hashCode())

func V2Complement

func V2Complement(subExprs interface{}, src *Col, result *map[uint64]struct{}) (err error)

Calculate complement of sub query results.

func V2EvalAllIDs

func V2EvalAllIDs(src *Col, result *map[uint64]struct{}) (err error)

Put all document IDs into result.

func V2EvalUnion

func V2EvalUnion(exprs []interface{}, src *Col, result *map[uint64]struct{}) (err error)

Calculate union of sub-query results.

func V2IntRange

func V2IntRange(intFrom interface{}, expr map[string]interface{}, src *Col, result *map[uint64]struct{}) (err error)

Scan hash table or collection documents using an integer range.

func V2Intersect

func V2Intersect(subExprs interface{}, src *Col, result *map[uint64]struct{}) (err error)

Calculate intersection of sub query results.

func V2Lookup

func V2Lookup(lookupValue interface{}, expr map[string]interface{}, src *Col, result *map[uint64]struct{}) (err error)

Execute value equity check ("attribute == value") using hash lookup or collection scan.

func V2PathExistence

func V2PathExistence(hasPath interface{}, expr map[string]interface{}, src *Col, result *map[uint64]struct{}) (err error)

Execute value existence check.

func V2RegexpLookup

func V2RegexpLookup(lookupRegexp interface{}, expr map[string]interface{}, src *Col, result *map[uint64]struct{}) (err error)

Execute value match regexp using hash lookup or collection scan.

Types

type Col

type Col struct {
	Data                                    *file.ColFile              // Data file
	Config                                  *Config                    // Index configuration
	Dir, ConfigFileName, ConfBackupFileName string                     // Directory and file names
	StrHT                                   map[string]*file.HashTable // Index path to Hash Table mapping
	StrIC                                   map[string]*IndexConf      // Index path to index configuration mapping
}

func OpenCol

func OpenCol(dir string) (col *Col, err error)

Open a collection.

func (*Col) BackupAndSaveConf

func (col *Col) BackupAndSaveConf() error

Copy existing index configuration to backup, then save the latest index configuration.

func (*Col) Close

func (col *Col) Close()

Close the collection.

func (*Col) Delete

func (col *Col) Delete(id uint64)

Delete a document by ID.

func (*Col) DeleteByUID

func (col *Col) DeleteByUID(uid string)

Delete a document by UID.

func (*Col) DeserializeAll

func (col *Col) DeserializeAll(template interface{}, fun func(id uint64) bool)

Deserialize each document into template (pointer to an initialized struct), invoke the function on the deserialized document (Collection Scan).

func (*Col) DurableDelete

func (col *Col) DurableDelete(id uint64) error

Delete a document and immediately flush all buffers.

func (*Col) DurableInsert

func (col *Col) DurableInsert(doc interface{}) (id uint64, err error)

Insert a new document and immediately flush all buffers.

func (*Col) DurableUpdate

func (col *Col) DurableUpdate(id uint64, doc interface{}) (newID uint64, err error)

Update a document and immediately flush all buffers.

func (*Col) Flush

func (col *Col) Flush() error

Flush collection data and index files.

func (*Col) ForAll

func (col *Col) ForAll(fun func(id uint64, doc interface{}) bool)

Deserialize each document and invoke the function on the deserialized docuemnt (Collection Scsn).

func (*Col) Index

func (col *Col) Index(path []string) error

Create a new index. Do not operate on this collection until it finishes!

func (*Col) IndexDoc

func (col *Col) IndexDoc(id uint64, doc interface{})

Put the document on all indexes.

func (*Col) Insert

func (col *Col) Insert(doc interface{}) (id uint64, err error)

Insert a new document.

func (*Col) InsertWithUID

func (col *Col) InsertWithUID(doc interface{}) (newID uint64, newUID string, err error)

Insert a new document, and assign it a UID.

func (*Col) LoadConf

func (col *Col) LoadConf() error

Load index configurations, and open each index file.

func (*Col) Read

func (col *Col) Read(id uint64, doc interface{}) error

Retrieve document by ID.

func (*Col) ReadByUID

func (col *Col) ReadByUID(uid string, doc interface{}) (uint64, error)

Retrieve documentby UID, return its ID.

func (*Col) ReassignUID

func (col *Col) ReassignUID(id uint64) (newID uint64, newUID string, err error)

Give a document (identified by ID) a new UID.

func (*Col) Unindex

func (col *Col) Unindex(path []string) error

Remove an index. Do not operate on this collection until it finishes!

func (*Col) UnindexDoc

func (col *Col) UnindexDoc(id uint64, doc interface{})

Remove the document from all indexes.

func (*Col) Update

func (col *Col) Update(id uint64, doc interface{}) (newID uint64, err error)

Update a document, return its new ID.

func (*Col) UpdateByUID

func (col *Col) UpdateByUID(uid string, doc interface{}) (newID uint64, err error)

Identify a document using UID and update it, return its new ID.

type Config

type Config struct {
	Indexes []IndexConf
}

type DB

type DB struct {
	Dir    string          // Database directory path
	StrCol map[string]*Col // Collection name to collection mapping
}

func OpenDB

func OpenDB(dir string) (db *DB, err error)

Open a database.

func (*DB) Close

func (db *DB) Close()

Close all collections.

func (*DB) Create

func (db *DB) Create(name string) (err error)

Create a collection.

func (*DB) Drop

func (db *DB) Drop(name string) (err error)

Drop (delete) a collection.

func (*DB) Flush

func (db *DB) Flush()

Flush all collection data and index files.

func (*DB) Rename

func (db *DB) Rename(oldName, newName string) (err error)

Rename a collection.

func (*DB) Scrub

func (db *DB) Scrub(name string) (err error)

Repair damaged documents/indexes, collect unused space along the way.

func (*DB) Use

func (db *DB) Use(name string) *Col

Return collection reference by collection name. This function is safe for concurrent use.

type IndexConf

type IndexConf struct {
	FileName            string
	PerBucket, HashBits uint64
	IndexedPath         []string
}

Jump to

Keyboard shortcuts

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