-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdata.hpp
53 lines (46 loc) · 1.2 KB
/
data.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef STUDENT_DATA_DATABASE_HEADER
#define STUDENT_DATA_DATABASE_HEADER
#include "sqlite_orm/sqlite_orm.h"
namespace database {
struct ClassList
{
int id;
std::string className;
};
auto OpenDB()
{
using namespace sqlite_orm;
auto DB = make_storage( "data.db" ,
make_table("class",
make_column("id",&ClassList::id,primary_key().autoincrement()),
make_column("class",&ClassList::className)
)
);
DB.sync_schema();
return DB;
}
void addClass(std::string className)
{
ClassList i;
i.className = className;
OpenDB().insert(i);
}
void deleteClass(std::string className)
{
using namespace sqlite_orm;
OpenDB().remove_all<ClassList>(where(c(&ClassList::className) == className));
}
std::string getClassJSON()
{
auto classes = OpenDB().get_all<ClassList>();
std::string start = "{\"data\":[";
for(auto & i : classes)
{
start += "\"" + i.className + "\",";
}
start = start.substr(0,start.size()-1);
start+="]}";
return start;
}
}
#endif