-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (65 loc) · 2.02 KB
/
main.cpp
File metadata and controls
80 lines (65 loc) · 2.02 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "person.pb.h"
#include "persons.pb.h"
#include "proto_db_convertor.hpp"
#include <iostream>
#include <memory>
#include <sqlite3.h>
#include "proto_c_mapper.hpp"
using namespace proto_mapper;
struct PersonS {
int age;
char name[20];
std::string temp;
std::vector<int> numbers;
std::vector<std::string> alas;
};
PROTO_MAPER(PROTO::Person, PersonS, DEFAULT_P2C_CONVERT,
DEFAULT_C2P_CONVERT,
PROTO_MEMBER(PersonS, char *, name),
PROTO_MEMBER(PersonS, std::string, temp),
PROTO_MEMBER(PersonS, std::vector<int>, numbers),
PROTO_MEMBER(PersonS, std::vector<std::string>, alas),
PROTO_MEMBER(PersonS, int, age));
int main() {
PROTO::Person msg;
msg.set_name("test");
msg.set_age(3);
auto sqLite = std::make_shared<SafeSQLite>("safe.sqlite");
ProtoDBConvertor<PROTO::Person> personConv(
sqLite, "name", {"numbers", "alas"}, true);
personConv.create_table();
personConv.write(msg);
personConv.write({msg, msg, msg});
auto res = personConv.read();
for (auto &r : res) {
std::cout << r.ShortDebugString() << std::endl;
}
PROTO::Persons ps;
ps.set_group_id("test");
ps.set_count(5);
ps.add_people()->CopyFrom(msg);
ps.add_people()->CopyFrom(msg);
ProtoDBConvertor<PROTO::Persons> personsConv(sqLite, "group_id", {"people"},
true);
personsConv.write(ps);
auto pses = personsConv.read();
for (auto &r : pses) {
std::cout << r.ShortDebugString() << std::endl;
}
auto pses2 = personsConv.read("select * from Persons where count = 5;");
for (auto &r : pses) {
std::cout << r.ShortDebugString() << std::endl;
}
PROTO::Person person;
person.set_age(18);
person.set_name("Tom");
person.add_numbers(1);
person.add_numbers(2);
person.add_alas("fuck");
person.add_alas("fuck2");
person.set_temp("fuck");
auto pc = PersonSPBMapper::toC(person);
auto person2 = PersonSPBMapper::toP(pc);
std::cout << person2.ShortDebugString() << std::endl;
return 0;
}