dboo::odb::fetch

template<class results_t>
size_t fetch(std::vector<results_t*>& objects, fetch_options options = {});                   1)
template<class results_t>
size_t fetch(std::vector<std::unique_ptr<results_t>>& objects, fetch_options options = {});   2)
size_t fetch ( std::vector<internalized_instance>& results, fetch_options options = {} );     3)
[size_t fetch ( std::vector<object_meta_data>& meta_data, fetch_options options = {} );       4)]
size_t fetch ( std::vector<obj_id>& object_ids, fetch_options options = {} );                 5)
size_t fetch ( std::vector<obj_ref>& objects, fetch_options options = {} );                   6)
size_t fetch ( format& output, fetch_options options = {} );                                  7)
fetch( objects )  1)

Returns objects matching an expression in an earlier call to dboo::odb::select or 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 repeatedly until all objects have been returned.

1

Returns objects in provided vector/array

2

Returns objects in provided vector of unique_ptrs

3

Returns objects in provided vector of internalized_instance

4

Returns meta data (not implemented yet with new database core)

5

Returns object ids in provided vector

6

Returns obj_ref in provided vector, they can be cast to normal pointers.

7

Outputs objects 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

result_t

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

Parameters

objects

An empty array which will be filled with the found objects.

object_ids

An empty array which will be filled with ids of the found objects.

results

An empty array which will be filled with internalized_instances of the found objects.

meta_data

An empty array which will be filled with meta data of the found objects.

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

Return value

Number of objects returned.

Exceptions

Example

#include <dboo/rfx.h>
#include <dboo/odb.h>
#include <dboo/osl/format_json.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");

    std::vector<std::unique_ptr<B>> results;

    db.select<B>(results);

    while ( db.last_query_has_more() ) { // loop until there are no more to retrieve
        results.clear();
        db.fetch ( results );  // fetch remaining objects
    }

    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 = [];

db.query(results, "select<B>()");

while ( db.last_query_has_more() ) { // loop until there are no more to retrieve
    results = []
    db.fetch ( results );  // fetch remaining objects
}