You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -17,6 +24,7 @@ SQLite ORM light header only library for modern C++
17
24
***Built with modern C++14 features (no macros and external scripts)**
18
25
***CRUD support**
19
26
***Pure select query support**
27
+
***UNION, EXCEPT and INTERSECT support**
20
28
***STL compatible**
21
29
***Custom types binding support**
22
30
***BLOB support** - maps to `std::vector<char>` or one can bind your custom type
@@ -47,7 +55,7 @@ struct User{
47
55
std::string firstName;
48
56
std::string lastName;
49
57
int birthDate;
50
-
std::shared_ptr<std::string> imageUrl;
58
+
std::unique_ptr<std::string> imageUrl;
51
59
int typeId;
52
60
};
53
61
@@ -93,7 +101,7 @@ More details about making storage can be found in [tutorial](https://github.com/
93
101
Let's create and insert new `User` into database. First we need to create a `User` object with any id and call `insert` function. It will return id of just created user or throw exception if something goes wrong.
94
102
95
103
```c++
96
-
User user{-1, "Jonh", "Doe", 664416000, std::make_shared<std::string>("url_to_heaven"), 3 };
104
+
User user{-1, "Jonh", "Doe", 664416000, std::make_unique<std::string>("url_to_heaven"), 3 };
Probably you may not like throwing exceptions. Me too. Exception `std::system_error` is thrown because return type in `get` function is not nullable. You can use alternative version `get_no_throw` which returns `std::shared_ptr` and doesn't throw `not_found_exception` if nothing found - just returns `nullptr`.
129
+
Probably you may not like throwing exceptions. Me too. Exception `std::system_error` is thrown because return type in `get` function is not nullable. You can use alternative version `get_pointer` which returns `std::unique_ptr` and doesn't throw `not_found_exception` if nothing found - just returns `nullptr`.
122
130
123
131
```c++
124
-
if(auto user = storage.get_no_throw<User>(insertedId)){
132
+
if(auto user = storage.get_pointer<User>(insertedId)){
`std::shared_ptr` is used as optional in `sqlite_orm`. Of course there is class optional in C++14 located at `std::experimental::optional`. But we don't want to use it until it is `experimental`.
139
+
`std::unique_ptr` is used as optional in `sqlite_orm`. Of course there is class optional in C++14 located at `std::experimental::optional`. But we don't want to use it until it is `experimental`.
132
140
133
141
We can also update our user. It updates row by id provided in `user` object and sets all other non `primary_key` fields to values stored in the passed `user` object. So you can just assign members to `user` object you want and call `update`
`iterate` member function returns adapter object that has `begin` and `end` member functions returning iterators that fetch object on dereference operator call.
182
190
183
-
CRUD functions `get`, `get_no_throw`, `remove`, `update` (not `insert`) work only if your type has a primary key column. If you try to `get` an object that is mapped to your storage but has no primary key column a `std::system_error` will be thrown cause `sqlite_orm` cannot detect an id. If you want to know how to perform a storage without primary key take a look at `date_time.cpp` example in `examples` folder.
191
+
CRUD functions `get`, `get_pointer`, `remove`, `update` (not `insert`) work only if your type has a primary key column. If you try to `get` an object that is mapped to your storage but has no primary key column a `std::system_error` will be thrown cause `sqlite_orm` cannot detect an id. If you want to know how to perform a storage without primary key take a look at `date_time.cpp` example in `examples` folder.
0 commit comments