dboo::odb::select

template<class selected_type, class result_t>
size_t select(std::vector<result_t*>& results, fetch_options options = {});   1)
template<class selected_type, class result_t>
size_t select(std::set<result_t*>& results, fetch_options options = {});      1)
template<class selected_type, class result_t>
size_t select(std::list<result_t*>& results, fetch_options options = {});     1)
template<class result_t>
size_t select(const std::string& clsid, std::set<result_t*>& results, fetch_options options = {});   1)
template<class result_t>
size_t select(const std::string& clsid, std::vector<result_t*>& results, fetch_options options = {}); 1)
template<class result_t>
size_t select(const std::string& clsid, std::list<result_t*>& results, fetch_options options = {});   1)
template<class selected_type, class result_t>
size_t select(std::vector<result_t*>& results, FieldComparison* expression, fetch_options options = {});   2)
template<class selected_type, class result_t>
size_t select(std::set<result_t*>& results, FieldComparison* expression, fetch_options options = {});      2)
template<class selected_type, class result_t>
size_t select(std::list<result_t*>& results, FieldComparison* expression, fetch_options options = {});     2)
template<class selected_type, class result_t>
size_t select(std::vector<result_t*>& results, SetComparison* expression, fetch_options options = {});     2)
template<class selected_type, class result_t>
size_t select(std::set<result_t*>& results, SetComparison* expression, fetch_options options = {});        2)
template<class selected_type, class result_t>
size_t select(std::list<result_t*>& results, SetComparison* expression, fetch_options options = {});       2)
template<class selected_type, class result_t>
size_t select(std::vector<std::unique_ptr<result_t>>& results, fetch_options options = {});   3)
template<class selected_type, class result_t>
size_t select(std::vector<std::unique_ptr<result_t>>& results, FieldComparison* expression, fetch_options options = {});  4)
template<class selected_type, class result_t>
size_t select(std::vector<std::unique_ptr<result_t>>& results, SetComparison* expression, fetch_options options = {});    4)
size_t select(const std::string& clsid, std::vector<internalized_instance>& results, fetch_options options = {}); 5)
size_t select(const std::string& clsid, std::vector<internalized_instance>& results, FieldComparison* expression, fetch_options options = {});   6)
size_t select(const std::string& clsid, std::vector<internalized_instance>& results, SetComparison* expression, fetch_options options = {}); 6)
size_t select(const std::string& clsid, format& output, fetch_options options = {} );  7)
size_t select(const std::string& clsid, format& output, FieldComparison* expression, fetch_options options = {}); 8)
size_t select(const std::string& clsid, format& output, SetComparison* expression, fetch_options options = {}); 8)
n/a

Returns the objects matching an expression. For Node.js, use the function dboo::odb::query. A maximum number of items are returned, by default this is 10000 but can be modified with fetch_options. The remaining objects can subsequently be retrieved by calling dboo::odb::fetch until all objects have been returned.

1

Selects all objects of specified class and puts them in provided container. Either use class type as template parameter or class name as string to specify class.

2

Selects objects matching expression and puts them in provided container. std::vector, std::set or std::list can be used as result containers.

3

Selects all objects of specified class and puts them in provided vector of unique_ptrs.

4

Selects objects matching expression and puts them in provided vector of unique_ptrs.

5

Selects all objects matching expression and puts them in provided vector of internalized_instance. With this call there is no internalization to runtime. Instead, the data is stored in a in-memory structure that can be accessed with index operator to access fields. The classes do not have to exist as types in application.

6

Selects objects matching expression and puts them in provided vector of internalized_instance. With this call there is no internalization to runtime. Instead, the data is stored in a in-memory structure that can be accessed with index operator to access fields. The classes do not have to exist as types in application.

7

Selects all objects of specified class and outputs them to the provided formatter. With the formatter the objects can be output as json or xml. The classes do not have to exist as types in application.

8

Selects objects matching expression and outputs them to the provided formatter. With the formatter the objects can be output as json or xml. The classes do not have to exist as types in application.

Template Parameters

selected_type

The class to select.

result_t

The pointer type to return the objects as. Must be a pointer to selected_type or base class thereof.

Parameters

clsid

Instead of providing selected_type as a template parameter, the name of the class can be specified as a regular parameter.

results

The selected objects will be returned in the results container

expression

The expression defines a query for selecting on fields or combining sub expressions.

options

Fetch options givs some control on the returned set of objects:

fetch_option

Explanation

fetch_referenced_objects

Includes all referenced objects (only applies when return type is internalized_instance )

fetch_unlimited

Specifies that all objects should be returned with this call.

default_fetch_limit

Specifies that the number of objects returned are specified by the database configuration.

fetch_limit(number)

Limits the return to specified number of objects

output

If specifying a format object instead of a return container, the objects will be passed to the formatter instead. See dboo-format

Type requirements

The selected type must have been registered with the database with the dboo::odb::define method.

Return value

Number of returned objects.

Exceptions

Example

#include <dboo/rfx.h>
#include <dboo/odb.h>

class A {
public:
  inline static dboo::cls<A> cls{"A"};
  static void dboo_class_init(dboo::cls<A>& c) {
    c.member(&A::var1, "var1");
  }
private:
  int var1;
};

class B {
public:
  B() = default;
  B(A* a) : a{a} {}
  virtual ~B() = default;
  inline static dboo::cls<B> cls{"B"};
  static void dboo_class_init(dboo::cls<B>& c) {
    c.member(&A::a, "a");
  }
private:
  A* a;
};

int main() {

    using dboo::in;
    using dboo::gt;
    using dboo::select;

    dboo::odb db;

    db.connect("localhost", 8823,
              "my_database",
              "usr132",
              "password");

    vector<B*> results_b;
    vector<A*> results_a;

    db.select<B>(results_b); // Selects all B
    db.select<A>(results_a, gt("var1", 10)); // Selects all A with var1 greater than 1

    db.select<B>(results_b, in("a", select<A>(gt("var1", 10)))); // Selects all B pointing to an A
                                                                 // with var1 greater than 10

    db.select<B>(results_b, in("a", select<A>(gt("var1", 10)))); // Selects all B pointing to an A
                                                                 // with var1 greater than 10

    vector<unique_ptr<B>> results_b;
    db.select<B>(results_b, in("a", select<A>(gt("var1", 10)))); // Selects all B pointing to an A
                                                                 // with var1 greater than 10

    return 0;
}
const dboo = require('dboo');
const config = require('config');

dboo.argv(process.argv);

dbConfig = config.get('dbConfig');

class UserId {
  userId = "";
  screenName = "";
  constructor(userid = "", screenName = "") {
    this.userId = userid;
    this.screenName = screenName;
  }
};

dboo.class(UserId,
  [{"userId": dboo.string},
    {"screenName": dboo.string},
  ]
);


class User {
  userId = null;
  address = "";
  constructor(userid = null, address = "") {
    this.userId = userid;
    this.screenName = screenName;
  }
};

dboo.class(User,
  [{"userId": UserId},  // referencing a UserId object
    {"address": dboo.string},
  ]
);

dboo.init(); // Class declarations must come before init!

const db = new dboo.odb();
db.connect(dbConfig.host, Number(dbConfig.port),
            dbConfig.dbName, dbConfig.webUserName,
            dbConfig.webUserPwd);

let results_b = [];
let results_a = [];

db.query(results_b, "select<B>()"); // Selects all B
db.query(results_a, "select<A>(gt(var1, 10))"); // Selects all A with var1 greater than 1

db.query(results_b, "select<B>(in(a, select<A>(gt(var1, 10))))"); // Selects all B pointing to an A
                                                             // with var1 greater than 10

In Node.js, the method dboo::odb::query must be used instead of select.