From: adam Date: Mon, 5 Nov 2012 17:30:22 +0000 (+0700) Subject: #1 X-Git-Tag: v1.2.12~643^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9ce6fce5223d0575e67b7fe3e0ec4472fe457d30;p=platform%2Fupstream%2Fejdb.git #1 --- diff --git a/README.md b/README.md index a7d95d8..6bc4146 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,6 @@ On Debian/Ubuntu linux you can install it as follows: EJDB NodeJS API ---------------------------------- - ### EJDB.open(dbFile, openMode) @@ -150,9 +149,9 @@ Remove collection. Call variations: - rmCollection(cname) - rmCollection(cname, cb) - rmCollection(cname, prune, cb) + removeCollection(cname) + removeCollection(cname, cb) + removeCollection(cname, prune, cb) __Arguments__ @@ -177,11 +176,117 @@ Call variations: save(cname, json object, [cb]) save(cname, , [cb]) - * {String} cname Name of collection. +__Arguments__ + + * {String} **cname** Name of collection. * {Array|Object} jsarr Signle JSON object or array of JSON objects to save * {Function} `[cb]` Callback function with arguments: (error, {Array} of OIDs for saved objects) +-------------------------------------- + + +### load(cname, oid, cb) + +Loads JSON object identified OID from the collection. + +__Arguments__ + + * {String} cname Name of collection + * {String} oid Object identifier (OID) + * {Function} cb Callback function with arguments: (error, obj) + `obj`: Retrieved JSON object or NULL if it is not found. + + -------------------------------------- + + +### remove(cname, oid, cb) + +Removes JSON object from the collection. + +__Arguments__ + + * {String} cname Name of collection + * {String} oid Object identifier (OID) + * {Function} cb Callback function with arguments: (error) + + +-------------------------------------- + + +### find(cname, qobj, orarr, hints, cb) +Execute query on collection. +EJDB queries inspired by MongoDB (mongodb.org) and follows same philosophy. + + Supported queries: + - Simple matching of String OR Number OR Array value: + - {'json.field.path' : 'val', ...} + - $not Negate operation. + - {'json.field.path' : {'$not' : val}} //Field not equal to val + - {'json.field.path' : {'$not' : {'$begin' : prefix}}} //Field not begins with val + - $begin String starts with prefix + - {'json.field.path' : {'$begin' : prefix}} + - $gt, $gte (>, >=) and $lt, $lte for number types: + - {'json.field.path' : {'$gt' : number}, ...} + - $bt Between for number types: + - {'json.field.path' : {'$bt' : [num1, num2]}} + - $in String OR Number OR Array val matches to value in specified array: + - {'json.field.path' : {'$in' : [val1, val2, val3]}} + - $nin - Not IN + - $strand String tokens OR String array val matches all tokens in specified array: + - {'json.field.path' : {'$strand' : [val1, val2, val3]}} + - $stror String tokens OR String array val matches any token in specified array: + - {'json.field.path' : {'$stror' : [val1, val2, val3]}} + - $exists Field existence matching: + - {'json.field.path' : {'$exists' : true|false}} + + 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. + + QUERY HINTS (specified by `hints` argument): + - $max Maximum number in the result set + - $skip Number of skipped results in the result set + - $orderby Sorting order of query fields. + Eg: ORDER BY field1 ASC, field2 DESC + hints: { + "$orderby" : { + "field1" : 1, + "field2" : -1 + } + } + + Many C API query examples can be found in `tcejdb/testejdb/t2.c` test case. + + To traverse selected records cursor object is used: + - Cursor#next() Move cursor to the next record and returns true if next record exists. + - Cursor#hasNext() Returns true if cursor can be placed to the next record. + - Cursor#field(name) Retrieve value of the specified field of the current JSON object record. + - Cursor#object() Retrieve whole JSON object with all fields. + - Cursor#reset() Reset cursor to its initial state. + - Cursor#length Read-only property: Number of records placed into cursor. + - Cursor#pos Read/Write property: You can set cursor position: 0 <= pos < length + - Cursor#close() Closes cursor and free cursor resources. Cursor cant be used in closed state. + + Call variations of find(): + - find(cname, qobj, cb) + - find(cname, qobj, hints, cb) + - find(cname, qobj, qobjarr, cb) + - find(cname, qobj, qobjarr, hints, cb) + + __Arguments__ + + * {String} cname Name of collection + * {Object} qobj Main JSON query object + * {Array} `[orarr]` Array of additional OR query objects (joined with OR predicate). + * {Object} `[hints]` JSON object with query hints. + * {Function} cb Callback function with arguments: (error, cursor, count) where: + `cursor`: Cursor object to traverse records + `count`: Total number of selected records + + + EJDB C Library ================================== diff --git a/node/ejdb.js b/node/ejdb.js index 88e4090..323f2db 100644 --- a/node/ejdb.js +++ b/node/ejdb.js @@ -78,9 +78,9 @@ EJDB.prototype.ensureCollection = function(cname, copts) { * Remove collection. * * Call variations: - * - rmCollection(cname) - * - rmCollection(cname, cb) - * - rmCollection(cname, prune, cb) + * - removeCollection(cname) + * - removeCollection(cname, cb) + * - removeCollection(cname, prune, cb) * * @param {String} cname Name of collection. * @param {Boolean} [prune=false] If true the collection data will erased from disk. @@ -211,7 +211,7 @@ EJDB.prototype.remove = function(cname, oid, cb) { * } * * Many C API query examples can be found in `tcejdb/testejdb/t2.c` test case. - * * + * * To traverse selected records cursor object is used: * - Cursor#next() Move cursor to the next record and returns true if next record exists. * - Cursor#hasNext() Returns true if cursor can be placed to the next record.