Recast  1
Game with custom magic
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
SQLite.hpp
Go to the documentation of this file.
1 
12 #ifndef RECAST_SERVER_SQLITE_H
13 #define RECAST_SERVER_SQLITE_H
14 
15 #include <sqlite_orm/sqlite_orm.h>
16 #include "models/Player.hpp"
17 #include "models/User.hpp"
18 
19 inline auto create_db() {
20  using namespace sqlite_orm;
21  return make_storage("db.sqlite",
22  make_table("players",
23  make_column("id",
24  &Player::id,
25  autoincrement(),
26  primary_key()),
27  make_column("user_id",
29  make_column("pos_x",
32  make_column("pos_y",
35  make_column("pos_z",
37  &Player::getPosZ)),
38  make_table("users",
39  make_column("id",
40  &User::id,
41  autoincrement(),
42  primary_key()),
43  make_column("login",
44  &User::login,
45  unique()),
46  make_column("password",
48  make_column("player_id",
49  &User::playerId)));
50 }
51 
55 class SQLite {
56 public:
57  SQLite() { storage.sync_schema(); }
58 
59  User registerUser(std::string login, std::string password);
60 
61  User authUser(std::string login, std::string password);
62 
63  void update(Player player);
64 
65 private:
66  decltype(create_db()) storage = create_db();
67 };
68 
69 
70 #endif //RECAST_SERVER_SQLITE_H
Player file.
int id
Definition: User.hpp:20
void setPosY(double y)
Definition: Player.hpp:31
const double & getPosX() const
Definition: Player.hpp:28
const double & getPosY() const
Definition: Player.hpp:30
auto create_db()
Definition: SQLite.hpp:19
void setPosX(double x)
Definition: Player.hpp:29
int playerId
Definition: User.hpp:21
User registerUser(std::string login, std::string password)
Definition: SQLite.cpp:17
int id
Definition: Player.hpp:23
std::string login
Definition: User.hpp:22
This class helps to easily put or get var from DB. Using sqlite_orm and sqlite.
Definition: SQLite.hpp:55
std::string password
Definition: User.hpp:23
void setPosZ(double z)
Definition: Player.hpp:33
SQLite()
Definition: SQLite.hpp:57
const double & getPosZ() const
Definition: Player.hpp:32
void update(Player player)
Definition: SQLite.cpp:43
User - technical data of a player (login, password and other)
Definition: User.hpp:18
User authUser(std::string login, std::string password)
Definition: SQLite.cpp:32
int userId
Definition: Player.hpp:26
Player class. XP, Life points and other.
Definition: Player.hpp:19