db

package
v0.0.0-...-ae1e168 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2021 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

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.

func (*Col) UpdateBytesFunc

func (col *Col) UpdateBytesFunc(id int, update func(origDoc []byte) (newDoc []byte, err error)) error

UpdateBytesFunc will update a document bytes. update func will get current document bytes and should return bytes of updated document; updated document should be valid JSON; provided buffer could be modified (reused for returned value); non-nil error will be propagated back and returned from UpdateBytesFunc.

func (*Col) UpdateFunc

func (col *Col) UpdateFunc(id int, update func(origDoc map[string]interface{}) (newDoc map[string]interface{}, err error)) error

UpdateFunc will update a document. update func will get current document and should return updated document; provided document should NOT be modified; non-nil error will be propagated back and returned from UpdateFunc.

type DB

type DB struct {
	Config *data.Config
	// 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) ColExists

func (db *DB) ColExists(name string) bool

ColExists returns true only if the given collection name exists in the database.

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) ForceUse

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

ForceUse creates a collection if one does not yet exist. Returns collection handle. Panics on error.

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
y or Y : Canonical URL