MySQL Connector/C++ 9.1.0
MySQL connector library for C and C++ applications
|
Represents a database schema. More...
Public Member Functions | |
Schema (Session &sess, const string &name) | |
Construct an object representing the named schema. | |
Schema (Session &) | |
Construct an object representing the default schema of the session. More... | |
const string & | getName () const |
Get schema name. | |
Session & | getSession () |
Get Session object. | |
bool | existsInDatabase () const |
Check if this schema exists in the database. More... | |
Collection | createCollection (const string &name) |
Create a new collection in the schema. More... | |
template<typename... Rest> | |
Collection | createCollection (const string &name, Rest &&... rest) |
Create a new collection in the schema, optionally specifying creation options. More... | |
template<typename... Rest> | |
void | modifyCollection (const string &name, Rest &&... options) |
Modify a collection in the schema specifying modify options. More... | |
Collection | getCollection (const string &name, bool check_exists=false) |
Return an object representing a collection with the given name. More... | |
Table | getTable (const string &name, bool check_exists=false) |
Return an object representing a table or a view with the given name. More... | |
CollectionList | getCollections () |
Get a list of all collections in the schema. More... | |
StringList | getCollectionNames () |
Get a list of names of all collections in the schema. More... | |
TableList | getTables () |
Get a list of all tables and views in the schema. More... | |
StringList | getTableNames () |
Get a list of names of all tables and views in the schema. More... | |
Table | getCollectionAsTable (const string &name, bool check_exists=true) |
Return a table corresponding to the given collection. More... | |
void | dropCollection (const mysqlx::string &name) |
Drop the given collection from the schema. More... | |
Represents a database schema.
A Schema
instance can be obtained from Session::getSchema()
method:
or it can be directly constructed as follows:
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.
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. Construct an object representing the default schema of the session.
The default schema is the one specified by session creation options.
|
inline |
Check if this schema exists in the database.
|
inline |
Create a new collection in the schema.
Returns the created collection. Set reuse
flag to true to return an already existing collection with the same name. Otherwise, an attempt to create a collection which already exists throws an error.
|
inline |
Create a new collection in the schema, optionally specifying creation options.
Arguments following name
, if any, are used to construct CollectionOptions object. See CollectionOptions for possible ways of specifying the options.
Returns the created collection.
void modifyCollection | ( | const string & | name, |
Rest &&... | options | ||
) |
Modify a collection in the schema specifying modify options.
Arguments following name
are used to construct CollectionOptions object. See CollectionOptions for possible ways of specifying the options.
|
inline |
Return an object representing a collection with the given name.
To check if the collection actually exists in the database set check_existence
flag to true. Otherwise the returned object can refer to a non-existing collection. An attempt to use such a non-existing collection in a database operation throws an error.
check_exists
is false, on the other hand, no I/O is involved when creating a Collection
object. Return an object representing a table or a view with the given name.
To check if the table actually exists in the database set check_existence
flag to true. Otherwise the returned object can refer to a non-existing table. An attempt to use such a non-existing table in a database operation throws an error.
|
inline |
Get a list of all collections in the schema.
The returned value can be stored in a container that holds Collection
objects, such as std::vector<Collection>
.
|
inline |
Get a list of names of all collections in the schema.
The returned value can be stored in a container that holds strings, such as std::vector<string>
.
|
inline |
|
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.
check_exists
is false, on the other hand, no I/O is involved when creating the Table
object.
|
inline |
Drop the given collection from the schema.
This method silently succeeds if a collection with the given name does not exist.