Represents a session to a database. More...
#include <session.hpp>
Public Member Functions | |
session (persistence &p) | |
Creates a new session object from persistence. | |
template<class T > | |
object_ptr< T > | insert (T *obj) |
template<class Type , typename... Args> | |
object_ptr< Type > | insert (Args &&... args) |
template<class T > | |
void | remove (object_ptr< T > &optr) |
template<class T > | |
object_view< T > | select () |
Select all object of a specific type. | |
template<class T , class V > | |
object_ptr< T > | get (V id) |
template<class T > | |
object_ptr< T > | save (T *obj) |
Saves an object to the database. | |
template<class T > | |
object_ptr< T > | save (const object_ptr< T > &obj) |
Save an object on database. | |
void | flush () |
void | load () |
Loads all tables from database. | |
void | load (const std::string &name) |
Load a specific table by given name. | |
template<class T > | |
void | load () |
Load a specific table by given type. | |
transaction | begin () |
Starts a transaction. | |
object_store & | store () |
Return a reference to the underlying object_store. | |
const object_store & | store () const |
Return a const reference to the underlying object_store. | |
Represents a session to a database.
This class represents a session to a database identified by a persistence object.
Once a session object is instantiated one can insert, update and delete objects.
This session can also load the whole database into the underlying object_store.
|
explicit |
Creates a new session object from persistence.
p | The persistence object. |
transaction matador::session::begin | ( | ) |
Starts a transaction.
void matador::session::flush | ( | ) |
Flushes all stored changes to the database
|
inline |
Gets a certain object identified by its primary key and its type.
T | Type of the object to get |
V | Type of the primary key |
id | Primary key value |
|
inline |
Inserts an object of type Type into the object_store. On successful insertion an object_ptr element with the inserted object is returned.
Type | Type of the object to insert |
Args | Argument types of the constructor arguments |
args | Arguments to construct the object |
|
inline |
Inserts an object of type T into the object_store without writing it to the database. It returns an object_ptr of the inserted object.
T | Type of the object to be inserted |
obj | Object to be inserted |
void matador::session::load | ( | ) |
Loads all tables from database.
Loads all tables from database. All object are inserted into the underlying object_store.
|
inline |
Load a specific table by given type.
T | type of the table to load |
void matador::session::load | ( | const std::string & | name | ) |
Load a specific table by given name.
name | of the table to load |
|
inline |
Remove object from object store
T | Type of object to be removed |
optr | Object to be removed |
|
inline |
Save an object on database.
T | Type of object to save |
obj | Object to save |
|
inline |
Saves an object to the database.
T | Type of object to save |
obj | Object to save |
|
inline |
Select all object of a specific type.
T | Type of object to be selected |
object_store & matador::session::store | ( | ) |
Return a reference to the underlying object_store.
const object_store & matador::session::store | ( | ) | const |
Return a const reference to the underlying object_store.