* Main EJDB class that contains all database control methods. Instance should be created by EJDB::open
*/
+ /*
+ * Document-class: EJDBQuery
+ * :nodoc:
+ * Internal EJDB class
+ */
+
/*
* Document-class: EJDBResults
* Class for accessing EJDB query resuts. Access to results is provided by methods of {Enumerble}[http://ruby-doc.org/core-1.9.1/Enumerable.html] mixin.
rb_raise(rb_eRuntimeError, "%s", emsg);
}
-int nil_or_raise_ejdb_error(EJDB *ejdb) {
+VALUE nil_or_raise_ejdb_error(EJDB *ejdb) {
int ecode = ejdbecode(ejdb);
if (ecode != TCESUCCESS && ecode != TCENOREC) {
raise_ejdb_error(ejdb);
* call-seq:
* EJDB::open(path, mode) -> EJDB
*
- * Open database. Return database instance handle object. <br/>
+ * Open database. Return database instance handle object.
* Default open mode: JBOWRITER | JBOCREAT .
*
* - +path+ (String) - database main file name
* call-seq:
* ejdb.close -> nil
*
- * Close database.<br/>
+ * Close database.
* If database was not opened it does nothing.
*/
VALUE EJDB_close(VALUE self) {
* call-seq:
* ejdb.ensure_collection(collName, [copts]) -> nil
*
- * Automatically creates new collection if it does't exists. Collection options +copts+ applied only for newly created collection.<br/>
- * For existing collections +copts+ takes no effect. <br/>
+ * Automatically creates new collection if it does't exists. Collection options +copts+ applied only for newly created collection.
+ * For existing collections +copts+ takes no effect.
*
- * Collection options (copts): <br/>
+ * Collection options (copts):
* [:cachedrecords] Max number of cached records in shared memory segment. Default: 0
* [:records] Estimated number of records in this collection. Default: 65535.
* [:large] Specifies that the size of the database can be larger than 2GB. Default: false
EJDB* ejdb = getEJDB(self);
if (!ejdbrmcoll(ejdb, StringValuePtr(collName), RTEST(prune))) {
- raise_ejdb_error(ejdb);
+ raise_ejdb_error(ejdb);
}
return Qnil;
}
* call-seq:
* ejdb.save(collName, [obj1, …, objN, merge = false]) -> Array or Number or nil
*
- * Save/update specified hashes or Ruby objects in the collection. If collection with +collName+ does not exists it will be created. <br/>
+ * Save/update specified hashes or Ruby objects in the collection. If collection with +collName+ does not exists it will be created.
* Each persistent object has unique identifier (OID) placed in the _id property. If a saved object does not have _id it will be autogenerated.
- * To identify and update object it should contains _id property.<br/><br/>
+ * To identify and update object it should contains _id property.
*
* NOTE: Field names of passed objects may not contain $ and . characters, error condition will be fired in this case.
* - +collName+ (String) - name of collection
* - +obj+ (Hash or Object) - one or more objects to save
* - +merge+ (Hash or Object) - if true a saved objects will be merged with who's
*
- * <br/>
+ *
* Returns:
* - oid of saved object, as string, if single object provided in arguments
* - array of oids, in other case
* - +collName+ (String) - name of collection
* - +oid+ (String) - object identifier (OID)
*
- * <br/>
+ *
* Returns:
* - BSON object as hash
* - nil, if it is not found
}
-void prepare_query_hint(VALUE res, VALUE hints, char* hint) {
+void prepare_query_hint(VALUE res, VALUE hints, const char* hint) {
VALUE val = get_hash_option(hints, hint);
if (!NIL_P(val)) {
rb_hash_aset(res, rb_str_concat(rb_str_new2("$"), rb_str_new2(hint)), val);
* - 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
+ * - {"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:
* - $exists Field existence matching:
* - {"fpath" => {"$exists" => true|false}}
* - $icase Case insensitive string matching:
- * - {"fpath" => {"$icase" => "val1"}} //icase 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 type of string index.
* - $pullAll Batch version of $pull
* - {.., "$pullAll" => {"fpath" => [array of values to remove], ...}}
*
- * <br/>
+ *
* NOTE: It is better to execute update queries with `$onlycount=true` hint flag
- * or use the special +update+ method to avoid unnecessarily rows fetching.<br/><br/>
+ * or use the special +update+ method to avoid unnecessarily rows fetching.
*
* NOTE: Negate operations: $not and $nin not using indexes
- * so they can be slow in comparison to other matching operations.<br/><br/>
+ * so they can be slow in comparison to other matching operations.
*
- * NOTE: Only one index can be used in search query operation.<br/><br/>
+ * NOTE: Only one index can be used in search query operation.
*
* QUERY HINTS (specified by +hints+ argument):
* [:max] Maximum number in the result set
* [:orderby] Sorting order of query fields.
* [:onlycount] If `true` only count of matching records will be returned without placing records in result set.
* [:fields] Set subset of fetched fields
- * If a field presented in +:orderby+ clause it will be forced to include in resulting records.<br/>
- * Example:<br/>
+ * 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
+ * :orderby => { #ORDER BY field1 ASC, field2 DESC
* "field1" => 1,
* "field2" => -1
* },
- * :fields => { //SELECT ONLY {_id, field1, field2}
+ * :fields => { #SELECT ONLY {_id, field1, field2}
* "field1" => 1,
* "field2" => 1
* }
* }
*
- * Many C API query examples can be found in `tcejdb/testejdb/t2.c` test case.<br/><br/>
+ * Many C API query examples can be found in `tcejdb/testejdb/t2.c` test case.
*
* - +collName+ (String) - name of collection
* - +q+ (Hash or Object) - query object. In most cases it will be easier to use hash to specify EJDB queries
* will be recognized as +hints+ argument
* - +hints+ (Hash or Object) - object with query hints
*
- * <br/>
+ *
* Returns:
* - EJDBResults object, if no +:onlycount+ hint specified or :explain hint specified
* - results count as Number, otherwise
* will be recognized as +hints+ argument
* - +hints+ (Hash or Object) - object with query hints
*
- * <br/>
+ *
* Returns:
* - found object as hash, if no +:onlycount+ hint specified
* - nil, if no +:onlycount+ hint specified and nothing found
/*
* call-seq:
- * ejdb.update(collName, oid) -> EJDBResults or Number
+ * ejdb.update(collName, [q = {}, orarr = [], hints = {}]) -> EJDBResults or Number
*
* Convenient method to execute update queries.
*
* - $pull | pullAll Atomically removes all occurrences of value from field, if field is an array.
* - {.., "$pull" => {"fpath" => val1, "fpathN" => valN, ...}}
*
- * <br/>
+ *
* - +collName+ (String) - name of collection
* - +q+ (Hash or Object) - query object. In most cases it will be easier to use hash to specify EJDB queries
* - +orarr+ (Array) - array of additional OR query objects (joined with OR predicate). If 3rd argument is not array it
* will be recognized as +hints+ argument
* - +hints+ (Hash or Object) - object with query hints
*
- * <br/>
- * Returns:
+ *
* Returns:
* - EJDBResults object, with only +count+ and +log+ methods available if :explain hint specified
* - updated objects count as Number, otherwise
* Drop indexes of all types for BSON field path.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_drop_indexes(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXDROPALL);
* Optimize indexes of all types for BSON field path. Performs B+ tree index file optimization.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_optimize_indexes(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXOP);
* Ensure index presence of String type for BSON field path.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_ensure_string_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXSTR);
* Rebuild index of String type for BSON field path.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_rebuild_string_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXSTR | JBIDXREBLD);
* Drop index of String type for BSON field path.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_drop_string_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXSTR | JBIDXDROP);
* call-seq:
* ejdb.ensure_istring_index(collName, fpath) -> nil
*
- * Ensure index presence of IString type for BSON field path.<br/>
+ * Ensure index presence of IString type for BSON field path.
* IString is the special type of String index for case insensitive matching.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_ensure_istring_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXISTR);
* call-seq:
* ejdb.rebuild_istring_index(collName, fpath) -> nil
*
- * Rebuild index of IString type for BSON field path.<br/>
+ * Rebuild index of IString type for BSON field path.
* IString is the special type of String index for case insensitive matching.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_rebuild_istring_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXISTR | JBIDXREBLD);
* call-seq:
* ejdb.drop_istring_index(collName, fpath) -> nil
*
- * Drop index of IString type for BSON field path.<br/>
+ * Drop index of IString type for BSON field path.
* IString is the special type of String index for case insensitive matching.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_drop_istring_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXISTR | JBIDXDROP);
* Ensure index of Number type for BSON field path.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_ensure_number_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXNUM);
* Rebuild index of Number type for BSON field path.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_rebuild_number_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXNUM | JBIDXREBLD);
* Drop index of Number type for BSON field path.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_drop_number_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXNUM | JBIDXDROP);
* Ensure index presence of Array type for BSON field path.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_ensure_array_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXARR);
* Rebuild index of Array type for BSON field path.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_rebuild_array_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXARR | JBIDXREBLD);
* Drop index of Array type for BSON field path.
*
* - +collName+ (String) - name of collection
- * - +oid+ (String) - BSON field path
+ * - +fpath+ (String) - BSON field path
*/
VALUE EJDB_drop_array_index(VALUE self, VALUE collName, VALUE fpath) {
return EJDB_set_index_internal(self, collName, fpath, JBIDXARR | JBIDXDROP);
* call-seq:
* ejdb.get_db_meta -> Hash
*
- * Get hash that describes a database structure and collections.<br/>
+ * Get hash that describes a database structure and collections.
* Sample meta:
* {
* "collections" => [
* call-seq:
* EJDB::valid_oid_string?(oid) -> true|false
*
- * Returns true if argument string contains valid oid. <br/>
+ * Returns true if argument string contains valid oid.
*
* - +oid+ (String) - oid as string
*/
rb_define_private_method(ejdbBinaryClass, "initialize", RUBY_METHOD_FUNC(EJDB_binary_init), 1);
rb_define_method(ejdbBinaryClass, "each", RUBY_METHOD_FUNC(EJDB_binary_each), 0);
- /*
- * Internal EJDB class. :nodoc:
- */
ejdbQueryClass = rb_define_class("EJDBQuery", rb_cObject);
}
\ No newline at end of file