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.
78 lines
2.8 KiB
78 lines
2.8 KiB
#include <signal.h>
|
|
#include <sqlite3.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "iflytop/components/sqlite_orm/sqlite_orm.hpp"
|
|
using namespace sqlite_orm;
|
|
|
|
struct User {
|
|
int id;
|
|
std::string firstName;
|
|
int lastName;
|
|
std::string birthDate;
|
|
std::unique_ptr<std::string> imageUrl;
|
|
int typeId;
|
|
};
|
|
|
|
struct UserType {
|
|
int id;
|
|
std::string name;
|
|
};
|
|
|
|
int main(int argc, char const *argv[]) {
|
|
sqlite3 *db;
|
|
char *zErrMsg = 0;
|
|
int rc;
|
|
// rc = sqlite3_open("test.db", &db);
|
|
// if (rc) {
|
|
// fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
|
|
// exit(0);
|
|
// } else {
|
|
// fprintf(stderr, "Opened database successfully\n");
|
|
// }
|
|
// sqlite3_close(db);
|
|
{
|
|
auto storage = make_storage("./db.sqlite", //
|
|
make_table("users", //
|
|
make_column("id", &User::id), //
|
|
make_column("first_name", &User::firstName), //
|
|
make_column("last_name", &User::lastName), //
|
|
make_column("birth_date", &User::birthDate), //
|
|
make_column("image_url", &User::imageUrl), //
|
|
make_column("type_id", &User::typeId)), //
|
|
make_table("user_types", //
|
|
make_column("id", &UserType::id, primary_key().autoincrement()), //
|
|
make_column("name", &UserType::name, default_value("name_placeholder"))));
|
|
// storage.dump();
|
|
// storage.sync_schema(
|
|
storage.sync_schema();
|
|
|
|
storage.filename();
|
|
std::cout << "storage.filename():" << storage.filename() << std::endl;
|
|
storage.sync_schema();
|
|
|
|
storage.insert(User{1, "Nicola", 2, "1856", nullptr, 0});
|
|
storage.insert(User{-1, "Linus", 2, "1969", nullptr, 0});
|
|
storage.insert(User{-1, "Mark", 3, "1984", nullptr, 0});
|
|
|
|
auto allEmployees = storage.get_all<User>();
|
|
for (auto &employee : allEmployees) {
|
|
std::cout << employee.id << ' ' << employee.firstName << ' ' << employee.lastName << std::endl;
|
|
}
|
|
// storage.sync_schema();
|
|
}
|
|
|
|
return 0;
|
|
}
|