diff --git a/docs/database.md b/docs/database.md index 4e38613..610c435 100644 --- a/docs/database.md +++ b/docs/database.md @@ -16,10 +16,58 @@ database.connect("sqlite3://test.db"); ``` ## Create table -🚧🚧🚧 TODO 🚧🚧🚧 + +To create table in database use `createTable` method and pass model as template argument: + +```cpp +struct ObjectModel +{ + int id; + std::string name; + std::string email; + std::string password; + std::string created_at; + std::string updated_at; +}; + +database.createTable(); +``` + ## Delete table -🚧🚧🚧 TODO 🚧🚧🚧 + +To delete table from database use `deleteTable` method and pass model as template argument: + +```cpp +database.deleteTable(); +``` + ## Insert objects -🚧🚧🚧 TODO 🚧🚧🚧 + +To insert objects into database use `insertObjects` method and pass vector of objects as argument: + +```cpp +std::vector objects{ + {1, "name", "email", "password", "created_at", "updated_at"}, + {2, "name2", "email2", "password2", "created_at2", "updated_at2"} +}; + +database.insertObjects(objects); +``` + +You can also insert single object: + +```cpp +ObjectModel object{1, "name", "email", "password", "created_at", "updated_at"}; + +database.insertObject(object); +``` + ## Query objects -🚧🚧🚧 TODO 🚧🚧🚧 + +To query objects from database use `executeQuery` method and pass [query](query.md) as argument: + +```cpp +orm::Query query; + +auto queriedObjects = database.executeQuery(query); +``` diff --git a/docs/query.md b/docs/query.md index 3d566ec..2c6bc04 100644 --- a/docs/query.md +++ b/docs/query.md @@ -3,5 +3,53 @@ 1. [Build query](#build-query) 2. [Limit query](#limit-query) 3. [Offset query](#offset-query) +4. [Build query](#build-query) -🚧🚧🚧 TODO 🚧🚧🚧 \ No newline at end of file +## Build query + +To build query use `orm::Query` class. For example: + +```cpp +struct ObjectModel +{ + int id; + std::string name; + std::string email; + std::string password; + std::string created_at; + std::string updated_at; +}; + +orm::Query query; +``` + +it is builder class so you can chain methods: + +```cpp +orm::Query query; +query.limit(10).offset(10); +``` + +## Limit query + +To limit query use `limit` method: + +```cpp +query.limit(10); +``` + +## Offset query + +To offset query use `offset` method: + +```cpp +query.offset(10); +``` + +## Build query + +To build query use `buildQuery` method, it will return string with query: + +```cpp +auto queryString = query.buildQuery(); +``` \ No newline at end of file