Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wsekta committed Jan 13, 2024
1 parent 7dfe2e1 commit 62d96d5
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 5 deletions.
56 changes: 52 additions & 4 deletions docs/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectModel>();
```

## Delete table
🚧🚧🚧 TODO 🚧🚧🚧

To delete table from database use `deleteTable` method and pass model as template argument:

```cpp
database.deleteTable<ObjectModel>();
```

## Insert objects
🚧🚧🚧 TODO 🚧🚧🚧

To insert objects into database use `insertObjects` method and pass vector of objects as argument:

```cpp
std::vector<ObjectModel> 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<ObjectModel> query;
auto queriedObjects = database.executeQuery(query);
```
50 changes: 49 additions & 1 deletion docs/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🚧🚧🚧
## 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<ObjectModel> query;
```

it is builder class so you can chain methods:

```cpp
orm::Query<ObjectModel> 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();
```

0 comments on commit 62d96d5

Please sign in to comment.