Documentation ¶
Index ¶
- Constants
- func IsValidOidStr(oid string) bool
- func Open(path string, options int) (*Ejdb, *EjdbError)
- func Version() string
- type EjColl
- func (coll *EjColl) AbortTransaction() *EjdbError
- func (coll *EjColl) BeginTransaction() *EjdbError
- func (coll *EjColl) CommitTransaction() *EjdbError
- func (coll *EjColl) Count(query string, queries ...string) (int, *EjdbError)
- func (coll *EjColl) Find(query string, queries ...string) ([][]byte, *EjdbError)
- func (coll *EjColl) FindOne(query string, queries ...string) (*[]byte, *EjdbError)
- func (coll *EjColl) IsTransactionActive() bool
- func (coll *EjColl) LoadBson(oid string) []byte
- func (coll *EjColl) RmBson(oid string) bool
- func (coll *EjColl) SaveBson(bsdata []byte) (string, *EjdbError)
- func (coll *EjColl) SaveJson(j string) (string, *EjdbError)
- func (coll *EjColl) SetIndex(ipath string, flags int) *EjdbError
- func (coll *EjColl) Sync() (bool, *EjdbError)
- func (coll *EjColl) Update(query string, queries ...string) (int, *EjdbError)
- type EjCollOpts
- type EjQuery
- func (q *EjQuery) AddOr(orquery string) *EjdbError
- func (q *EjQuery) Count(coll *EjColl) (int, *EjdbError)
- func (q *EjQuery) Del()
- func (q *EjQuery) Execute(coll *EjColl) ([][]byte, *EjdbError)
- func (q *EjQuery) ExecuteOne(coll *EjColl) (*[]byte, *EjdbError)
- func (q *EjQuery) SetHints(hints string) *EjdbError
- type Ejdb
- func (ejdb *Ejdb) Close() *EjdbError
- func (ejdb *Ejdb) Command(bson []byte) (*[]byte, *EjdbError)
- func (ejdb *Ejdb) CreateColl(colname string, opts *EjCollOpts) (*EjColl, *EjdbError)
- func (ejdb *Ejdb) CreateQuery(query string, queries ...string) (*EjQuery, *EjdbError)
- func (ejdb *Ejdb) Del()
- func (ejdb *Ejdb) Export(path string, cnames *[]string, flags int) (log string, err *EjdbError)
- func (ejdb *Ejdb) GetColl(colname string) (*EjColl, *EjdbError)
- func (ejdb *Ejdb) GetColls() ([]*EjColl, *EjdbError)
- func (ejdb *Ejdb) Import(path string, cnames *[]string, flags int) (log string, err *EjdbError)
- func (ejdb *Ejdb) IsOpen() bool
- func (ejdb *Ejdb) JsonCommand(json string) (*[]byte, *EjdbError)
- func (ejdb *Ejdb) Meta() ([]byte, *EjdbError)
- func (ejdb *Ejdb) RmColl(colname string, unlinkfile bool) (bool, *EjdbError)
- func (ejdb *Ejdb) Sync() (bool, *EjdbError)
- type EjdbError
Constants ¶
const ( // Drop index. JBIDXDROP = C.JBIDXDROP // Drop index for all types. JBIDXDROPALL = C.JBIDXDROPALL // Optimize indexes. JBIDXOP = C.JBIDXOP // Rebuild index. JBIDXREBLD = C.JBIDXREBLD // Number index. JBIDXNUM = C.JBIDXNUM // String index.*/ JBIDXSTR = C.JBIDXSTR // Array token index. JBIDXARR = C.JBIDXARR // Case insensitive string index JBIDXISTR = C.JBIDXISTR )
Index modes, index types.
const ( // Open as a reader. JBOREADER = C.JBOREADER // Open as a writer. JBOWRITER = C.JBOWRITER // Create if db file not exists. JBOCREAT = C.JBOCREAT // Truncate db on open. JBOTRUNC = C.JBOTRUNC // Open without locking. JBONOLCK = C.JBONOLCK // Lock without blocking. JBOLCKNB = C.JBOLCKNB // Synchronize every transaction. JBOTSYNC = C.JBOTSYNC )
Database open modes
const ( // Invalid collection name. JBEINVALIDCOLNAME = C.JBEINVALIDCOLNAME // Invalid bson object. JBEINVALIDBSON = C.JBEINVALIDBSON // Invalid bson object id. JBEINVALIDBSONPK = C.JBEINVALIDBSONPK // Invalid query control field starting with '$'. JBEQINVALIDQCONTROL = C.JBEQINVALIDQCONTROL // $strand, $stror, $in, $nin, $bt keys requires not empty array value. JBEQINOPNOTARRAY = C.JBEQINOPNOTARRAY // Inconsistent database metadata. JBEMETANVALID = C.JBEMETANVALID // Invalid field path value. JBEFPATHINVALID = C.JBEFPATHINVALID // Invalid query regexp value. JBEQINVALIDQRX = C.JBEQINVALIDQRX // Result set sorting error. JBEQRSSORTING = C.JBEQRSSORTING // Query generic error. JBEQERROR = C.JBEQERROR // Updating failed. JBEQUPDFAILED = C.JBEQUPDFAILED // Only one $elemMatch allowed in the fieldpath. JBEQONEEMATCH = C.JBEQONEEMATCH // $fields hint cannot mix include and exclude fields JBEQINCEXCL = C.JBEQINCEXCL // action key in $do block can only be one of: $join JBEQACTKEY = C.JBEQACTKEY // Exceeded the maximum number of collections per database JBEMAXNUMCOLS = C.JBEMAXNUMCOLS )
Error codes
Variables ¶
This section is empty.
Functions ¶
func IsValidOidStr ¶
Return true if passed `oid` string cat be converted to valid 12 bit BSON object identifier (OID).
Types ¶
type EjColl ¶
type EjColl struct {
// contains filtered or unexported fields
}
An EJDB collection
func (*EjColl) AbortTransaction ¶
Abort transaction for EJDB collection.
func (*EjColl) BeginTransaction ¶
Begin transaction for EJDB collection.
func (*EjColl) CommitTransaction ¶
Commit transaction for EJDB collection.
func (*EjColl) Count ¶
Execute a query specified by JSON strings query, queries and return the number of results, not the results themselves. See the documentation of EjQuery for a description of the query format.
func (*EjColl) Find ¶
Execute a query specified by JSON strings query, queries and return the results as a slice of BSON objects See the documentation of EjQuery for a description of the query format.
func (*EjColl) FindOne ¶
Execute a query specified by JSON strings query, queries and return only the first result as a BSON object See the documentation of EjQuery for a description of the query format.
func (*EjColl) IsTransactionActive ¶
Get current transaction status. Return true if a transaction is active, false otherwise.
func (*EjColl) SaveBson ¶
Persist BSON object in the collection. If saved bson does't have _id primary key then `oid` will be set to generated bson _id, otherwise `oid` will be set to the current bson's _id field.
NOTE: Field names of passed `bs` object may not contain `$` and `.` characters,
error condition will be fired in this case.
BSON object must be a byte slice, for instance one created by the "labix.org/v2/mgo/bson" library
func (*EjColl) SaveJson ¶
Persist JSON string in the collection. If saved json does't have _id primary key then `oid` will be set to generated bson _id, otherwise `oid` will be set to the current json's _id field.
NOTE: Integer literals in the JSON string will be converted to float64
func (*EjColl) SetIndex ¶
Set index for JSON field in EJDB collection.
Available index types:
`JBIDXSTR` String index for JSON string values.
`JBIDXISTR` Case insensitive string index for JSON string values.
`JBIDXNUM` Index for JSON number values.
`JBIDXARR` Token index for JSON arrays and string values.
One JSON field can have several indexes for different types.
Available index operations:
`JBIDXDROP` Drop index of specified type.
Eg: flag = JBIDXDROP | JBIDXNUM (Drop number index)
`JBIDXDROPALL` Drop index for all types.
`JBIDXREBLD` Rebuild index of specified type.
`JBIDXOP` Optimize index of specified type. (Optimize the B+ tree index file)
Examples:
Set index for JSON path `addressbook.number` for strings and numbers: `ccoll.SetIndex("album.number", JBIDXSTR | JBIDXNUM)`
Set index for array: `ccoll.SetIndex("album.tags", JBIDXARR)`
Rebuild previous index: `ccoll.SetIndex("album.tags", JBIDXARR | JBIDXREBLD)`
type EjCollOpts ¶
type EjCollOpts struct { // Large collection. It can be larger than 2GB. Default false Large bool // Collection records will be compressed with DEFLATE compression. Default: false Compressed bool // Expected records number in the collection. Default: 128K Records int // Maximum number of cached records. Default: 0 CachedRecords int }
EJDB collection tuning options
type EjQuery ¶
type EjQuery struct {
// contains filtered or unexported fields
}
An EJDB query
func (*EjQuery) Count ¶
Execute the query and only return the number of results it returned, not the results themselves
func (*EjQuery) Del ¶
func (q *EjQuery) Del()
Delete the query. This must be called in order to not leak memory.
func (*EjQuery) ExecuteOne ¶
Execute the query and return only the first result as a BSON object
func (*EjQuery) SetHints ¶
Set query hints. `hints` is a JSON string
- $max Maximum number in the result set
- $skip Number of skipped results in the result set
- $orderby Sorting order of query fields.
- $fields Set subset of fetched fields If a field presented in $orderby clause it will be forced to include in resulting records. Example: hints: { "$orderby" : { //ORDER BY field1 ASC, field2 DESC "field1" : 1, "field2" : -1 }, "$fields" : { //SELECT ONLY {_id, field1, field2} "field1" : 1, "field2" : 1 } }
type Ejdb ¶
type Ejdb struct {
// contains filtered or unexported fields
}
An EJDB database
func (*Ejdb) Close ¶
Close a table database object. If a writer opens a database but does not close it appropriately, the database will be broken. If successful return true, otherwise return false.
func (*Ejdb) Command ¶
Execute ejdb database command.
Supported commands:
Exports database collections data. See ejdbexport() method.
"export" : { "path" : string, //Exports database collections data "cnames" : [string array]|null, //List of collection names to export "mode" : int|null //Values: null|`JBJSONEXPORT` See ejdbexport() method }
Command response: { "log" : string, //Diagnostic log about executing this command "error" : string|null, //ejdb error message "errorCode" : int|0, //ejdb error code }
Imports previously exported collections data into ejdb.
"import" : { "path" : string //The directory path in which data resides "cnames" : [string array]|null, //List of collection names to import "mode" : int|null //Values: null|`JBIMPORTUPDATE`|`JBIMPORTREPLACE` See ejdbimport() method }
Command response: { "log" : string, //Diagnostic log about executing this command "error" : string|null, //ejdb error message "errorCode" : int|0, //ejdb error code }
func (*Ejdb) CreateColl ¶
func (ejdb *Ejdb) CreateColl(colname string, opts *EjCollOpts) (*EjColl, *EjdbError)
Same as GetColl() but automatically creates new collection if it doesn't exists.
func (*Ejdb) CreateQuery ¶
Create query object. Sucessfully created queries must be destroyed with Query.Del().
EJDB queries inspired by MongoDB (mongodb.org) and follows same philosophy.
Supported queries:
Simple matching of String OR Number OR Array value:
{'fpath' : 'val', ...}
$not Negate operation.
{'fpath' : {'$not' : val}} //Field not equal to val
{'fpath' : {'$not' : {'$begin' : prefix}}} //Field not begins with val
$begin String starts with prefix
{'fpath' : {'$begin' : prefix}}
$gt, $gte (>, >=) and $lt, $lte for number types:
{'fpath' : {'$gt' : number}, ...}
$bt Between for number types:
{'fpath' : {'$bt' : [num1, num2]}}
$in String OR Number OR Array val matches to value in specified array:
{'fpath' : {'$in' : [val1, val2, val3]}}
$nin - Not IN
$strand String tokens OR String array val matches all tokens in specified array:
{'fpath' : {'$strand' : [val1, val2, val3]}}
$stror String tokens OR String array val matches any token in specified array:
{'fpath' : {'$stror' : [val1, val2, val3]}}
$exists Field existence matching:
{'fpath' : {'$exists' : true|false}}
$icase Case insensitive string matching:
{'fpath' : {'$icase' : 'val1'}} //icase matching Ignore case matching with '$in' operation:
{'name' : {'$icase' : {'$in' : ['théâtre - театр', 'hello world']}}} For case insensitive matching you can create special index of type: `JBIDXISTR`
$elemMatch The $elemMatch operator matches more than one component within an array element.
{ array: { $elemMatch: { value1 : 1, value2 : { $gt: 1 } } } } Restriction: only one $elemMatch allowed in context of one array field.
Queries can be used to update records:
$set Field set operation.
{.., '$set' : {'field1' : val1, 'fieldN' : valN}} $upsert Atomic upsert. If matching records are found it will be '$set' operation, otherwise new record will be inserted with fields specified by argment object.
{.., '$upsert' : {'field1' : val1, 'fieldN' : valN}} $inc Increment operation. Only number types are supported.
{.., '$inc' : {'field1' : number, ..., 'field1' : number} $dropall In-place record removal operation.
{.., '$dropall' : true} $addToSet Atomically adds value to the array only if its not in the array already. If containing array is missing it will be created.
{.., '$addToSet' : {'fpath' : val1, 'fpathN' : valN, ...}} $addToSetAll Batch version if $addToSet
{.., '$addToSetAll' : {'fpath' : [array of values to add], ...}} $pull Atomically removes all occurrences of value from field, if field is an array.
{.., '$pull' : {'fpath' : val1, 'fpathN' : valN, ...}} $pullAll Batch version of $pull
{.., '$pullAll' : {'fpath' : [array of values to remove], ...}}
- Collection joins supported in the following form:
{..., $do : {fpath : {$join : 'collectionname'}} } Where 'fpath' value points to object's OIDs from 'collectionname'. Its value can be OID, string representation of OID or array of this pointers. NOTE: Negate operations: $not and $nin not using indexes so they can be slow in comparison to other matching operations. NOTE: Only one index can be used in search query operation.
func (*Ejdb) Del ¶
func (ejdb *Ejdb) Del()
Delete database object. If the database is not closed, it is closed implicitly. Note that the deleted object and its derivatives can not be used anymore
func (*Ejdb) Export ¶
Exports database collections data to the specified directory. Database read lock will be taken on each collection.
NOTE: Only data exported as BSONs can be imported with `Ejdb.Import()`
`path` is the directory path in which data will be exported. `cnames` is a list of collection names to export. `nil` implies that all existing collections will be exported. `flags` can be set to `JBJSONEXPORT` in order to export data as JSON files instead exporting into BSONs. Export() returns the log for the operation as a string
func (*Ejdb) GetColl ¶
Retrieve collection handle for collection specified `collname`. If collection with specified name does't exists it will return nil.
func (*Ejdb) GetColls ¶
Return a slice containing shallow copies of all collection handles (EjColl) currently open.
func (*Ejdb) Import ¶
Imports previously exported collections data into ejdb. Global database write lock will be applied during import operation.
NOTE: Only data exported as BSONs can be imported with `Ejdb.Import()`
`path` is the directory path in which data resides. `cnames` is a list of collection names to import. `nil` implies that all collections found in `path` will be imported. `flags` can be one of:
`JBIMPORTUPDATE` Update existing collection entries with imported ones. Existing collections will not be recreated. For existing collections options will not be imported. `JBIMPORTREPLACE` Recreate existing collections and replace all their data with imported entries. Collections options will be imported. `0` Implies `JBIMPORTUPDATE`
Import() returns the log for the operation as a string