matador::session Class Reference

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_storestore ()
 Return a reference to the underlying object_store.
 
const object_storestore () const
 Return a const reference to the underlying object_store.
 

Detailed Description

Represents a session to a database.

This class represents a session to a database identified by a persistence object.

matador::persistence p(<database connection string>);
p.attach<person>("person");
The connection class represents a connection to a database.
Definition connection.hpp:25
Represents the persistence layer for a database and an object_store.
Definition persistence.hpp:30
Represents a session to a database.
Definition session.hpp:42

Once a session object is instantiated one can insert, update and delete objects.

s.insert(new person("georg"));

This session can also load the whole database into the underlying object_store.

Constructor & Destructor Documentation

◆ session()

matador::session::session ( persistence p)
explicit

Creates a new session object from persistence.

Parameters
pThe persistence object.

Member Function Documentation

◆ begin()

transaction matador::session::begin ( )

Starts a transaction.

Returns
The started transaction object

◆ flush()

void matador::session::flush ( )

Flushes all stored changes to the database

◆ get()

template<class T , class V >
object_ptr< T > matador::session::get ( id)
inline

Gets a certain object identified by its primary key and its type.

Template Parameters
TType of the object to get
VType of the primary key
Parameters
idPrimary key value
Returns
The found object or an empty object

◆ insert() [1/2]

template<class Type , typename... Args>
object_ptr< Type > matador::session::insert ( Args &&...  args)
inline

Inserts an object of type Type into the object_store. On successful insertion an object_ptr element with the inserted object is returned.

Template Parameters
TypeType of the object to insert
ArgsArgument types of the constructor arguments
Parameters
argsArguments to construct the object
Returns
Inserted object contained by an object_ptr on success.

◆ insert() [2/2]

template<class T >
object_ptr< T > matador::session::insert ( T *  obj)
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.

Template Parameters
TType of the object to be inserted
Parameters
objObject to be inserted
Returns
object_ptr of the inserted object

◆ load() [1/3]

void matador::session::load ( )

Loads all tables from database.

Loads all tables from database. All object are inserted into the underlying object_store.

◆ load() [2/3]

template<class T >
void matador::session::load ( )
inline

Load a specific table by given type.

Template Parameters
Ttype of the table to load

◆ load() [3/3]

void matador::session::load ( const std::string &  name)

Load a specific table by given name.

Parameters
nameof the table to load

◆ remove()

template<class T >
void matador::session::remove ( object_ptr< T > &  optr)
inline

Remove object from object store

Template Parameters
TType of object to be removed
Parameters
optrObject to be removed

◆ save() [1/2]

template<class T >
object_ptr< T > matador::session::save ( const object_ptr< T > &  obj)
inline

Save an object on database.

Template Parameters
TType of object to save
Parameters
objObject to save
Returns
Saved object

◆ save() [2/2]

template<class T >
object_ptr< T > matador::session::save ( T *  obj)
inline

Saves an object to the database.

Template Parameters
TType of object to save
Parameters
objObject to save
Returns
Saved object

◆ select()

template<class T >
object_view< T > matador::session::select ( )
inline

Select all object of a specific type.

Template Parameters
TType of object to be selected
Returns
object_view containing the selection

◆ store() [1/2]

object_store & matador::session::store ( )

Return a reference to the underlying object_store.

Returns
A reference to the object_store.

◆ store() [2/2]

const object_store & matador::session::store ( ) const

Return a const reference to the underlying object_store.

Returns
A const reference to the object_store.

The documentation for this class was generated from the following file:
  • matador/orm/session.hpp