- Connect
- Create table
- Delete table
- Insert objects
- Query objects
- Transactions
Connect
To connect to database create its object and connect it with standard connection string:
database.
connect(
"sqlite3://test.db");
A class representing a database in the ORM framework.
Definition database.hpp:17
auto connect(const std::string &connectionString) -> void
Connects to a database.
Create table
To create table in database use createTable
method and pass model as template argument:
struct ObjectModel
{
int id;
std::string name;
std::string email;
std::string password;
std::string created_at;
std::string updated_at;
};
auto createTable() -> void
Execute a create table query for a model.
Definition database.hpp:104
Delete table
To delete table from database use deleteTable
method and pass model as template argument:
auto deleteTable() -> void
Execute a delete table query for a model.
Definition database.hpp:119
Insert objects
To insert objects into database use insert
method and pass vector of objects as argument:
std::vector<ObjectModel> objects{
{1, "name", "email", "password", "created_at", "updated_at"},
{2, "name2", "email2", "password2", "created_at2", "updated_at2"}
};
auto insert(const std::vector< T > &objects) -> void
Executes a insert query for multiple objects.
Definition database.hpp:72
You can also insert single object:
ObjectModel object{1, "name", "email", "password", "created_at", "updated_at"};
Query objects
To select objects from database use select
method and pass select as argument:
auto queriedObjects = database.
select(query);
auto select(Query< T > &query) -> std::vector< T >
Executes a select query and returns the result.
Definition database.hpp:47
A template class representing a select query in the ORM framework.
Definition query.hpp:20
Transactions
To use transaction use database's transactionBegin
method followed by transactionCommit
or transactionRollback
:
database.transactionBegin();
database.transactionCommit();
or:
database.transactionBegin();
database.transactionRollback();