ASqlModel#
Defines a model that can be stored in an SQL database. Implements queries for this type to the database (insert, update, select, delete)
Header: | #include <AUI/Data/ASqlModel.h> |
CMake: | aui_link(my_target PUBLIC aui::data) |
Detailed Description#
Model should implement AModelMeta (see AUI/Data/AModelMeta.h)
Public Types#
NoSuchRowException#
class ASqlModel::NoSuchRowException
Thrown when a single row is expected to be received, but the database did not return any rows.
Empty structure.
TooManyRowsException#
class ASqlModel::TooManyRowsException
Thrown when one row is expected to be received, but the database returned more than one row.
Empty structure.
IncompleteSelectRequest#
class ASqlModel::IncompleteSelectRequest
Empty structure.
Public Methods#
byId#
Get a row from the table by ID.
- Arguments
id
ID of the required string- Returns
- the string table for the specified ID \throws NoSuchRowException if no string was found for the specified ID
getIdColumnNameInOtherTables#
static AString ASqlModel::getIdColumnNameInOtherTables()
- Returns
- name of the relation column for other tables.
Example:
struct User -> table users -> column user_id is the result.
hasMany#
template<typename Other >
_<typenameOther::IncompleteSelectRequest> ASqlModel::hasMany()
Implementation of one-to-many relation between ORM structures. Used with belongsTo.
User::getPosts() -> hasMany()
|-- Post::getAuthor() -> belongsTo()
|-- Post::getAuthor() -> belongsTo()
|-- Post::getAuthor() -> belongsTo()
....
- Returns
- incomplete SQL request (see ASqlModel::IncompleteSelectRequest)
make#
Creates a model and saves it to the database.
- Arguments
args
the constructor arguments- Returns
- the ORM structure
Examples#
examples/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
ass::BackgroundSolid { AColor::RED },
} });
setContents(Centered {
Vertical {
_new<ADropdownList>(AListModel<AString>::make({ "one-way flight", "return flight" })) AUI_LET {
connect(it->selectionId().readProjected([](int selectionId) { return selectionId == 1; }),
mIsReturnFlight);
},
dateTextField(mDepartureDate),
dateTextField(mReturnDate) AUI_LET { connect(mIsReturnFlight, AUI_SLOT(it)::setEnabled); },
remove#
Removes row from the table by ID.
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.