AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ASqlModel< Model > Struct Template Reference

Defines a model that can be stored in an SQL database. Implements queries for this type to the database (insert, update, select, delete) More...

#include <AUI/Data/ASqlModel.h>

Classes#

class  IncompleteSelectRequest
 
class  NoSuchRowException
 Thrown when a single row is expected to be received, but the database did not return any rows. More...
 
class  TooManyRowsException
 Thrown when one row is expected to be received, but the database returned more than one row. More...
 

Public Types#

typedef AModelMeta< Model > Meta
 

Public Member Functions#

void save ()
 Saves this model in DB. If id = 0 then a new row will be created in the table, and the id of the created row will be assigned in the structure field. If id != 0 then the existing row in the table will be updated.
 
void remove ()
 Removes row from the table by ID.
 

Static Public Member Functions#

static _< IncompleteSelectRequestwhere (const ASqlBuilder::WhereStatement::WhereExpr &expression)
 
static Model byId (id_t id)
 Get a row from the table by ID.
 
static _< IncompleteSelectRequestall ()
 
template<typename ... Args>
static Model make (Args &&... args)
 Creates a model and saves it to the database.
 
static AString getIdColumnNameInOtherTables ()
 

Signals and public fields#

id_t id = 0
 

Protected Member Functions#

template<typename Other>
_< typename Other::IncompleteSelectRequest > hasMany ()
 Implementation of one-to-many relation between ORM structures. Used with belongsTo.
 
template<typename Other>
Other belongsTo (id_t desiredId)
 

Detailed Description#

template<typename Model>
struct ASqlModel< Model >
Template Parameters
ModelORM model.
Note
Model should implement AModelMeta (see AUI/Data/AModelMeta.h)

Member Function Documentation#

◆ byId()#

template<typename Model>
static Model ASqlModel< Model >::byId ( id_t id)
inlinestatic
Parameters
idID of the required string
Returns
the string table for the specified ID
Exceptions
NoSuchRowExceptionif no string was found for the specified ID

◆ getIdColumnNameInOtherTables()#

template<typename Model>
static AString ASqlModel< Model >::getIdColumnNameInOtherTables ( )
inlinestatic
Returns
name of the relation column for other tables.

Example: struct User -> table users -> column user_id is the result.

◆ hasMany()#

template<typename Model>
template<typename Other>
_< typename Other::IncompleteSelectRequest > ASqlModel< Model >::hasMany ( )
inlineprotected
User::getPosts() -> hasMany<Post>()
  |-- Post::getAuthor() -> belongsTo<Post>()
  |-- Post::getAuthor() -> belongsTo<Post>()
  |-- Post::getAuthor() -> belongsTo<Post>()
  ....
Template Parameters
OtherORM model relation will created with
Returns
incomplete SQL request (see ASqlModel::IncompleteSelectRequest)
See also
ASqlModel::IncompleteSelectRequest

◆ make()#

template<typename Model>
template<typename ... Args>
static Model ASqlModel< Model >::make ( Args &&... args)
inlinestatic
Template Parameters
Argsthe types of constructor arguments
Parameters
argsthe constructor arguments
Returns
the ORM structure