dboo::odb::request
template<class T>
T* request(const object_name& name); 1)
template<class T>
T* request(const obj_id& id); 2)
void request(obj_ref& object, const object_name& name); 3)
void request(obj_ref& object, const obj_id& id); 4)
request(name) : Object 1)
request(hex_id) : Object 2)
Returns the objects matching the object ids.
- 1
Returns the object associated with specified name from server.
- 2
Returns the object associated with specified object id from server.
- 3
Returns the object (as an obj_ref) associated with specified name from server.
- 4
Returns the object (as an obj_ref) associated with specified object id from server.
Parameters
- name
A string associated with an object in an earlier call to commit.
- id
An object id.
- hex_id
A 16 or 18 character long hex string with an object id. Either just the 16 hex numbers of a 64 bit id, or 16 characters prefixed with 0x.
Return value
An object.
Exceptions
- exception_named_object_does_not_exist
The name is not associated with an object.
- exception_unknown_objects
An object with the specified id does not exist.
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() {
dboo::odb db;
db.connect("localhost", 8823,
"my_database",
"usr132",
"password");
auto a = db.request<B>("AnotherObject"); // Both the B associated with the name "AnotherObject"
// and the A pointed to by B::a will be fetched from the database
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 a = db.request("AnotherUser"); // Both the User associated with the name "AnotherUser"
// and the UserId pointed to by User.userId will be fetched from the database