Represents a database schema.
A Schema
instance can be obtained from Session::getSchema()
method:
Session session;
mySchema= session.getSchema("My Schema");
Schema(Session &sess, const string &name)
Construct an object representing the named schema.
Definition: xdevapi.h:2110
or it can be directly constructed as follows:
Session session;
Schema mySchema(session,
"My Schema");
Each Schema
instance is tied to a particular session and all the operations on the schema and its objects are performed using that session. If the session is destroyed, an attempt to use a schema of that session yields an error.
When creating a Schema
object, by default no checks are made that it actually exists in the database. An operation that is executed on the server and involves such a non-existent schema throws an error.
- Note
- A
Schema
object should be used by at most one thread at a time. It is not safe to call its methods by several threads simultaneously. It is responsibility of the user to ensure this using a synchronization mechanism such as mutexes.
Table getCollectionAsTable |
( |
const string & |
name, |
|
|
bool |
check_exists = true |
|
) |
| |
|
inline |
Return a table corresponding to the given collection.
The table has two columns: _id
and doc
. For each document in the collection there is one row in the table with doc
filed holding the document as a JSON value and _id
field holding document's identifier.
To check if the collection actually exists in the database set check_existence
flag to true. Otherwise the returned table can refer to a non-existing collection. An attempt to use such a non-existing collection table throws an error.
- Note
- Checking the existence of a collection involves communication with the server. If
check_exists
is false, on the other hand, no I/O is involved when creating the Table
object.