Overview
The queries in DBOO returns objects. You can make selection on member fields to return only objects with for example an double value greater than certain number, or a string field matching a regular expression.
Other ways of returning objects includes traversing graphs with dboo::ref smart pointers which provide a way of lazy loading of objects. See dboo::ref. Yet another way is to request by object id or by a given object name.
Selecting all objects of a class:
select < class > ()
Selecting based on values of a field:
select < class > ( ValueComparator ( Field, Value ) )
select < class > ( SetComparator ( Field, Value ) )
See Value comparator and Set comparator.
Using sub queries and combining results:
select < class > ( SetOperator ( Field, Value ) )
See Set operator.
C++
In C++ you use the query API, which is a set of functions that builds the query. The main functions for queries are found in dboo::odb:
A few examples:
// Returns all MyClass with _field == 10.0:
vector<MyClass*> results;
db.select<MyClass>(results, eq("_field", 10.0));
// Returns the number of MyClass with _field == 10.0:
auto count = db.count<MyClass>(eq("_field", 10.0));
// Erases all MyClass with _field == 10.0:
db.erase<MyClass>(eq("_field", 10.0));
It is possible to use query strings in C++ as well, but the query functions provide at least some compile time checks. The grammar for query strings is the same as on command line or in Node.js.
Node.js
In Node.js, the function dboo::odb::query is used with a string query. The grammar follows C++, with some differences. See Grammar.
// Returns all MyClass with _field == 10.0:
let results = [];
db.query(results, "select<MyClass>(eq(_field, 10.0))");
// Returns the number of MyClass with _field == 10.0:
auto count = db.query("count<MyClass>(eq(_field, 10.0))");
// Erases all MyClass with _field == 10.0:
db.query("erase<MyClass>(eq(_field, 10.0))");
DBOO Command line
On the command line the same query language as in Node.js is used:
> dboo example_queries -u=example_user -p=password
dboo example_user@example_queries> select<Customer>(match(_name,'Olympia.*'))
{"dboo::objectid" : "4a00887c09c8007e", "dboo::class" : "Customer", "_email" : "op6732@p12.com", "_name" : "Olympia Powell", "_purchases" : ["4a00887c09c80018", "4a00887c09c80024", "4a00887c09c80028", "4a00887c09c80033", "4a00887c09c80038", "4a00887c09c80040", "4a00887c09c80041", "4a00887c09c80042", "4a00887c09c80054", "4a00887c09c80055", "4a00887c09c80057", "4a00887c09c80058", "4a00887c09c8005d", "4a00887c09c8005f", "4a00887c09c80067"]}
dboo example_user@example_queries> count<Customer>(match(_name,'Olympia.*'))
1
dboo example_user@example_queries> erase<Customer>(match(_name,'Olympia.*'))
dboo example_user@example_queries> count<Customer>(match(_name,'Olympia.*'))
0
See also the DBOO manager guide: