db

package
Version: v0.0.0-...-40a7436 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2015 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Overview

Collection schema and index management.

Collection and DB storage management.

Document management and index maintenance.

Query processor.

Index

Constants

View Source
const (
	DOC_DATA_FILE   = "dat_" // Prefix of partition collection data file name.
	DOC_LOOKUP_FILE = "id_"  // Prefix of partition hash table (ID lookup) file name.
	INDEX_PATH_SEP  = "!"    // Separator between index keys in index directory name.
)
View Source
const (
	PART_NUM_FILE = "number_of_partitions" // DB-collection-partition-number-configuration file name
)

Variables

This section is empty.

Functions

func Complement

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

Calculate complement of sub-query results.

func EvalAllIDs

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

Put all document IDs into result.

func EvalQuery

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

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

func EvalUnion

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

Calculate union of sub-query results.

func GetIn

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

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

func IntRange

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

Look for indexed integer values within the specified integer range.

func Intersect

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

Calculate intersection of sub-query results.

func Lookup

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

Value equity check ("attribute == value") using hash lookup.

func PathExistence

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

Value existence check (value != nil) using hash lookup.

func StrHash

func StrHash(str string) int

Hash a string using sdbm algorithm.

Types

type Col

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

Collection has data partitions and some index meta information.

func OpenCol

func OpenCol(db *DB, name string) (*Col, error)

Open a collection and load all indexes.

func (*Col) AllIndexes

func (col *Col) AllIndexes() (ret [][]string)

Return all indexed paths.

func (*Col) ApproxDocCount

func (col *Col) ApproxDocCount() int

Return approximate number of documents in the collection.

func (*Col) Delete

func (col *Col) Delete(id int) error

Delete a document.

func (*Col) ForEachDoc

func (col *Col) ForEachDoc(fun func(id int, doc []byte) (moveOn bool))

Do fun for all documents in the collection.

func (*Col) ForEachDocInPage

func (col *Col) ForEachDocInPage(page, total int, fun func(id int, doc []byte) bool)

Divide the collection into roughly equally sized pages, and do fun on all documents in the specified page.

func (*Col) Index

func (col *Col) Index(idxPath []string) (err error)

Create an index on the path.

func (*Col) Insert

func (col *Col) Insert(doc map[string]interface{}) (id int, err error)

Insert a document into the collection.

func (*Col) InsertRecovery

func (col *Col) InsertRecovery(id int, doc map[string]interface{}) (err error)

Insert a document with the specified ID into the collection (incl. index). Does not place partition/schema lock.

func (*Col) Read

func (col *Col) Read(id int) (doc map[string]interface{}, err error)

Find and retrieve a document by ID.

func (*Col) Unindex

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

Remove an index.

func (*Col) Update

func (col *Col) Update(id int, doc map[string]interface{}) error

Update a document.

type DB

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

Database structures.

func OpenDB

func OpenDB(dbPath string) (*DB, error)

Open database and load all collections & indexes.

func (*DB) AllCols

func (db *DB) AllCols() (ret []string)

Return all collection names.

func (*DB) Close

func (db *DB) Close() error

Close all database files. Do not use the DB afterwards!

func (*DB) Create

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

Create a new collection.

func (*DB) Drop

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

Drop a collection and lose all of its documents and indexes.

func (*DB) Dump

func (db *DB) Dump(dest string) error

Copy this database into destination directory (for backup).

func (*DB) Rename

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

Rename a collection.

func (*DB) Scrub

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

Scrub a collection - fix corrupted documents and de-fragment free space.

func (*DB) Truncate

func (db *DB) Truncate(name string) error

Truncate a collection - delete all documents and clear

func (*DB) Use

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

Use the return value to interact with collection. Return value may be nil if the collection does not exist.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL