/
UCS
/
sqlite_orm
Обзор
Документация
Войти
/
UCS
/
sqlite_orm
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v1.8
examples/check.cpp
62 строки
2 KB
fnc12
changed PointerAlignment from Right to Left
21 ноя 2020, 20:38
21 ноя 2020, 20:38
1eaff43
Код
Авторство
О чём код?
#include <sqlite_orm/sqlite_orm.h> #include <string> #include <iostream> using namespace sqlite_orm; using std::cout; using std::endl; int main() { struct Contact { int id = 0; std::string firstName; std::string lastName; std::string email; std::string phone; }; struct Product { int id = 0; std::string name; float listPrice = 0; float discount = 0; }; auto storage = make_storage(":memory:", make_table("contacts", make_column("contact_id", &Contact::id, primary_key()), make_column("first_name", &Contact::firstName), make_column("last_name", &Contact::lastName), make_column("email", &Contact::email), make_column("phone", &Contact::phone), check(length(&Contact::phone) >= 10)), make_table("products", make_column("product_id", &Product::id, primary_key()), make_column("product_name", &Product::name), make_column("list_price", &Product::listPrice), make_column("discount", &Product::discount, default_value(0)), check(c(&Product::listPrice) >= &Product::discount and c(&Product::discount) >= 0 and c(&Product::listPrice) >= 0))); storage.sync_schema(); try { storage.insert(Contact{0, "John", "Doe", {}, "408123456"}); } catch(const std::system_error& e) { cout << e.what() << endl; } storage.insert(Contact{0, "John", "Doe", {}, "(408)-123-456"}); try { storage.insert(Product{0, "New Product", 900, 1000}); } catch(const std::system_error& e) { cout << e.what() << endl; } try { storage.insert(Product{0, "New XFactor", 1000, -10}); } catch(const std::system_error& e) { cout << e.what() << endl; } return 0; }