You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

2 years ago
  1. #include <sqlite_orm/sqlite_orm.h>
  2. #include <string>
  3. #include <vector>
  4. #include <iostream>
  5. #include <cassert>
  6. using std::cout;
  7. using std::endl;
  8. struct User {
  9. int id;
  10. std::string name;
  11. std::vector<char> hash; // binary format
  12. };
  13. int main(int, char**) {
  14. using namespace sqlite_orm;
  15. auto storage = make_storage("blob.sqlite",
  16. make_table("users",
  17. make_column("id", &User::id, primary_key()),
  18. make_column("name", &User::name),
  19. make_column("hash", &User::hash)));
  20. storage.sync_schema();
  21. storage.remove_all<User>();
  22. User alex{
  23. 0,
  24. "Alex",
  25. {0x10, 0x20, 0x30, 0x40},
  26. };
  27. alex.id = storage.insert(alex);
  28. cout << "users count = " << storage.count<User>() << endl;
  29. cout << "alex = " << storage.dump(storage.get<User>(alex.id)) << endl;
  30. auto hash = storage.get<User>(alex.id).hash;
  31. assert(hash.size() == 4);
  32. assert(hash[0] == 0x10);
  33. assert(hash[1] == 0x20);
  34. assert(hash[2] == 0x30);
  35. assert(hash[3] == 0x40);
  36. return 0;
  37. }