Hyper API for C++ 0.0.20746
Hyper client library for C++ applications
|
The catalog class gives access to the metadata of the attached databases of a connection. More...
#include <Catalog.hpp>
Public Member Functions | |
Catalog (const Catalog &)=delete | |
Catalog & | operator= (const Catalog &)=delete |
Catalog (Catalog &&)=delete | |
Catalog | operator= (Catalog &&)=delete |
bool | hasTable (const TableName &table) const |
Checks whether a table with the given name exists. | |
TableDefinition | getTableDefinition (const TableName &tableName) const |
Gets the table definition for an existing table. | |
void | createSchema (const SchemaName &schemaName) const |
Creates a SQL schema with the given name. | |
void | createSchemaIfNotExists (const SchemaName &schemaName) const |
Creates a SQL schema with the given name. | |
void | createTable (const hyperapi::TableDefinition &table_definition) const |
Creates a SQL table with the given table definition. | |
void | createTableIfNotExists (const hyperapi::TableDefinition &table_definition) const |
Creates a SQL table with the given table definition. | |
std::unordered_set< SchemaName > | getSchemaNames () const |
Gets the name of all schemas in the first database in the database search path. | |
std::unordered_set< SchemaName > | getSchemaNames (const DatabaseName &database) const |
Gets the names of all schemas in database . | |
std::unordered_set< TableName > | getTableNames (const SchemaName &schema) const |
Gets the names of all tables in the given schema. | |
void | createDatabase (const std::string &databasePath) |
Creates a database file with the given path. | |
void | createDatabaseIfNotExists (const std::string &databasePath) |
Creates a database file with the given path if it doesn't exist yet. | |
void | detachDatabase (const DatabaseName &databaseName) |
Detaches a database from the underlying connection. | |
void | attachDatabase (const std::string &databasePath, const DatabaseName &databaseName) |
Attaches a database file databasePath to the underlying connection under the name databaseName . | |
void | attachDatabase (const std::string &databasePath) |
Attaches a database file databasePath to the underlying connection. | |
void | detachAllDatabases () |
Detaches all databases from the underlying connection. | |
void | dropDatabase (const std::string &databasePath) |
Drops the database with the given path. | |
void | dropDatabaseIfExists (const std::string &databasePath) |
Drops the database with the given path. | |
Connection & | getConnection () const noexcept |
Returns the underlying connection. | |
The catalog class gives access to the metadata of the attached databases of a connection.
It can be used to obtain information about certain schema objects, such as tables, to query the set of existing schema objects, and to manipulate those objects.
All manipulations and queries of this class could also be written in raw SQL. The catalog class is merely a convenience wrapper.
Definition at line 31 of file Catalog.hpp.
void hyperapi::Catalog::attachDatabase | ( | const std::string & | databasePath | ) |
Attaches a database file databasePath
to the underlying connection.
Use the stem of the databasePath
as name. E.g., "foo/bar.hyper" will use the name "bar"
databasePath | The path to the database file |
HyperException | in case of error |
void hyperapi::Catalog::attachDatabase | ( | const std::string & | databasePath, |
const DatabaseName & | databaseName | ||
) |
Attaches a database file databasePath
to the underlying connection under the name databaseName
.
databasePath | The path to the database file |
databaseName | The name for the database |
HyperException | in case of error |
void hyperapi::Catalog::createDatabase | ( | const std::string & | databasePath | ) |
Creates a database file with the given path.
Does not attach to it automatically. If a relative path is given, it will be relative to the working directory of the Hyper instance.
databasePath | The path for the new database. Has to end with ".hyper". |
HyperException | in case of error |
void hyperapi::Catalog::createDatabaseIfNotExists | ( | const std::string & | databasePath | ) |
Creates a database file with the given path if it doesn't exist yet.
Does not attach to it automatically. If a relative path is given, it will be relative to the working directory of the Hyper instance. Note: This method will throw if a file with the given path exists that is not a valid hyper database.
databasePath | The path for the new database. Has to end with ".hyper". |
HyperException | in case of error |
void hyperapi::Catalog::createSchema | ( | const SchemaName & | schemaName | ) | const |
Creates a SQL schema with the given name.
The method will throw if a schema with this name already exists.
schemaName | The name of the schema. |
HyperException | in case of error |
void hyperapi::Catalog::createSchemaIfNotExists | ( | const SchemaName & | schemaName | ) | const |
Creates a SQL schema with the given name.
The method will just silently do nothing if a schema with this name already exists.
schemaName | The name of the schema. |
HyperException | in case of error |
void hyperapi::Catalog::createTable | ( | const hyperapi::TableDefinition & | table_definition | ) | const |
Creates a SQL table with the given table definition.
The method will throw if a table with this name already exists.
table_definition | The definition of the table. |
HyperException | in case of error |
void hyperapi::Catalog::createTableIfNotExists | ( | const hyperapi::TableDefinition & | table_definition | ) | const |
Creates a SQL table with the given table definition.
The method will just silently do nothing if a table with this name already exists.
table_definition | The definition of the table. |
HyperException | in case of error |
void hyperapi::Catalog::detachAllDatabases | ( | ) |
Detaches all databases from the underlying connection.
If this connection was the only connection that was currently attached to these databases, then the database files will be unloaded, all updates will be written to disk, and the database file can be accessed externally (e.g., copied, moved, etc.).
HyperException | in case of error |
void hyperapi::Catalog::detachDatabase | ( | const DatabaseName & | databaseName | ) |
Detaches a database from the underlying connection.
databaseName | The name of the database. |
HyperException | in case of error |
void hyperapi::Catalog::dropDatabase | ( | const std::string & | databasePath | ) |
Drops the database with the given path.
If a relative path is given, it will be relative to the working directory of the Hyper instance. Dropping a database will delete the corresponding database file.
Throws if a database file with the given path doesn't exist.
databasePath | The path to the database. |
HyperException | in case of error |
void hyperapi::Catalog::dropDatabaseIfExists | ( | const std::string & | databasePath | ) |
Drops the database with the given path.
If a relative path is given, it will be relative to the working directory of the Hyper instance. Dropping a database will delete the corresponding database file.
Does nothing if a database file with the given path doesn't exist.
databasePath | The path to the database. |
HyperException | in case of error |
|
inlinenoexcept |
Returns the underlying connection.
Definition at line 221 of file Catalog.hpp.
std::unordered_set< SchemaName > hyperapi::Catalog::getSchemaNames | ( | ) | const |
Gets the name of all schemas in the first database in the database search path.
Note that by default, this is the single database that is attached if only one database is attached. When multiple databases are attached, the database search path is empty by default and this method will fail. The user can set the database search path in this case to specify from which database to retrieve schema names.
HyperException | in case of error |
std::unordered_set< SchemaName > hyperapi::Catalog::getSchemaNames | ( | const DatabaseName & | database | ) | const |
Gets the names of all schemas in database
.
database | The name of the database. |
HyperException | in case of error |
TableDefinition hyperapi::Catalog::getTableDefinition | ( | const TableName & | tableName | ) | const |
Gets the table definition for an existing table.
Note that the name of the table definition will always be fully qualified, even if the input name was not. E.g., if the user queries table "foo", which resolves to the table "db1"."bar"."foo", then the resulting TableDefinition
will have the latter set as name.
tableName | The name of the table. |
HyperException | in case of error |
std::unordered_set< TableName > hyperapi::Catalog::getTableNames | ( | const SchemaName & | schema | ) | const |
Gets the names of all tables in the given schema.
If the schema name does not specify a database, the first database in the schema_search_path is used.
schema | The (qualified) schema name. |
HyperException | in case of error |
bool hyperapi::Catalog::hasTable | ( | const TableName & | table | ) | const |
Checks whether a table with the given name exists.
table | The name of the table. |
HyperException | in case of error |