ORM C++
Loading...
Searching...
No Matches
orm::DatabaseCore Class Reference

A class representing a database in the ORM framework. More...

#include <database.hpp>

Inheritance diagram for orm::DatabaseCore:

Public Member Functions

 DatabaseCore ()
 Constructs a new Database object.
 DatabaseCore (db::CommandGeneratorFactory factory)
 Constructs a database with an application-supplied backend registry.
 DatabaseCore (const DatabaseCore &)=delete
 DatabaseCore (DatabaseCore &&)=delete
auto operator= (const DatabaseCore &) -> DatabaseCore &=delete
auto operator= (DatabaseCore &&) -> DatabaseCore &=delete
auto connect (const std::string &connectionString) -> void
 Connects to a database.
auto connect (db::BackendType requestedBackend, const std::string &connectionString) -> void
 Connects using an explicitly selected registered backend.
auto disconnect () -> void
 Disconnects from the database.
auto getBackendType () const noexcept -> db::BackendType
 Get the backend type of the database.
auto isConnected () const noexcept -> bool
 Returns whether a backend session is currently open.
auto getBackendCapabilities () const -> const db::BackendCapabilities &
 Returns the capabilities advertised by the connected backend.
auto beginTransaction () -> void
 Starts a transaction.
auto commitTransaction () -> void
 Commits a transaction.
auto rollbackTransaction () -> void
 Rollbacks a transaction.

Protected Member Functions

template<typename SchemaType, typename T>
auto selectImpl (Query< T > &query) -> std::vector< T >
 Executes a select query and returns the result.
template<typename SchemaType, typename Source, typename Result>
auto selectImpl (ProjectionQuery< Source, Result > &query) -> std::vector< Result >
 Executes a projection select query and returns DTO results.
template<typename SchemaType, typename T>
auto insertImpl (const std::vector< T > &objects) -> void
 Executes a insert query for multiple objects.
template<typename SchemaType, typename T>
auto insertImpl (T object) -> void
 Executes a insert query for a single object.
template<typename SchemaType, typename T>
auto updateImpl (const Update< T > &update) -> std::size_t
 Executes an update query.
template<typename SchemaType, typename T>
auto removeImpl (const query::Predicate &predicate) -> std::size_t
 Executes a delete query for rows matching a predicate.
template<typename SchemaType, typename T>
auto createTableImpl () -> void
 Execute a create table query for a model.
template<typename SchemaType, typename T>
auto deleteTableImpl () -> void
 Execute a delete table query for a model.
template<typename SchemaType, typename T>
auto createRelationTablesImpl () -> void
 Creates junction tables owned by a model's ManyToMany mappings.
template<typename SchemaType, typename T>
auto deleteRelationTablesImpl () -> void
 Drops junction tables owned by a model's ManyToMany mappings.
template<typename SchemaType, typename Owner, typename Target>
auto linkImpl (const Owner &owner, std::string_view relationField, const Target &target) -> std::size_t
 Creates or changes a OneToMany/ManyToMany association.
template<typename SchemaType, typename Owner, typename Target>
auto unlinkImpl (const Owner &owner, std::string_view relationField, const Target &target) -> std::size_t
 Removes a OneToMany/ManyToMany association.

Detailed Description

A class representing a database in the ORM framework.

This class provides functionality for connecting to a database and executing queries.

Member Function Documentation

◆ connect()

auto orm::DatabaseCore::connect ( const std::string & connectionString) -> void

Connects to a database.

Parameters
connectionStringThe connection string for the database.

◆ createRelationTablesImpl()

template<typename SchemaType, typename T>
auto orm::DatabaseCore::createRelationTablesImpl ( ) -> void
inlineprotected

Creates junction tables owned by a model's ManyToMany mappings.

Endpoint tables must already exist. Inverse mappings intentionally do not create the shared junction table.

◆ createTableImpl()

template<typename SchemaType, typename T>
auto orm::DatabaseCore::createTableImpl ( ) -> void
inlineprotected

Execute a create table query for a model.

Template Parameters
TThe type of the model which table to will be created.

◆ deleteTableImpl()

template<typename SchemaType, typename T>
auto orm::DatabaseCore::deleteTableImpl ( ) -> void
inlineprotected

Execute a delete table query for a model.

Template Parameters
TThe type of the model which table to will be deleted.

◆ getBackendCapabilities()

auto orm::DatabaseCore::getBackendCapabilities ( ) const -> const db::BackendCapabilities &
nodiscard

Returns the capabilities advertised by the connected backend.

Exceptions
DatabaseErrorwhen no backend is connected.

◆ getBackendType()

auto orm::DatabaseCore::getBackendType ( ) const -> db::BackendType
nodiscardnoexcept

Get the backend type of the database.

Returns
The backend type of the database.

◆ insertImpl() [1/2]

template<typename SchemaType, typename T>
auto orm::DatabaseCore::insertImpl ( const std::vector< T > & objects) -> void
inlineprotected

Executes a insert query for multiple objects.

Template Parameters
TThe type of the query.
Parameters
objectsThe vector of objects of type T to insert.

◆ insertImpl() [2/2]

template<typename SchemaType, typename T>
auto orm::DatabaseCore::insertImpl ( T object) -> void
inlineprotected

Executes a insert query for a single object.

Template Parameters
TThe type of the query.
Parameters
objectThe object of type T to insert.

◆ linkImpl()

template<typename SchemaType, typename Owner, typename Target>
auto orm::DatabaseCore::linkImpl ( const Owner & owner,
std::string_view relationField,
const Target & target ) -> std::size_t
inlineprotected

Creates or changes a OneToMany/ManyToMany association.

Returns
1 when database state changed, otherwise 0.

◆ removeImpl()

template<typename SchemaType, typename T>
auto orm::DatabaseCore::removeImpl ( const query::Predicate & predicate) -> std::size_t
inlineprotected

Executes a delete query for rows matching a predicate.

Template Parameters
TThe type of the model whose rows will be deleted.
Parameters
predicateThe required predicate used in the WHERE clause.
Returns
The number of affected rows.

◆ selectImpl() [1/2]

template<typename SchemaType, typename Source, typename Result>
auto orm::DatabaseCore::selectImpl ( ProjectionQuery< Source, Result > & query) -> std::vector< Result >
inlineprotected

Executes a projection select query and returns DTO results.

Template Parameters
SourceThe source ORM model.
ResultThe flat projection DTO.
Parameters
queryThe projection query to execute.
Returns
The vector of DTO objects returned by the projection query.

◆ selectImpl() [2/2]

template<typename SchemaType, typename T>
auto orm::DatabaseCore::selectImpl ( Query< T > & query) -> std::vector< T >
inlineprotected

Executes a select query and returns the result.

Template Parameters
TThe type of the query model.
Parameters
queryThe select query of type T to execute.
Returns
The vector of objects of type T returned by the select query.

◆ unlinkImpl()

template<typename SchemaType, typename Owner, typename Target>
auto orm::DatabaseCore::unlinkImpl ( const Owner & owner,
std::string_view relationField,
const Target & target ) -> std::size_t
inlineprotected

Removes a OneToMany/ManyToMany association.

Returns
1 when database state changed, otherwise 0.

◆ updateImpl()

template<typename SchemaType, typename T>
auto orm::DatabaseCore::updateImpl ( const Update< T > & update) -> std::size_t
inlineprotected

Executes an update query.

Template Parameters
TThe type of the query model.
Parameters
updateThe update builder with assignments and a required predicate.
Returns
The number of affected rows.

The documentation for this class was generated from the following file: