-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhyper_table.h
More file actions
73 lines (60 loc) · 1.63 KB
/
hyper_table.h
File metadata and controls
73 lines (60 loc) · 1.63 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
//
// Created by PengPremium on 17/3/5.
//
#ifndef HYPERNATE_TABLE_H
#define HYPERNATE_TABLE_H
#include <vector>
#include <unordered_set>
#include <json.hpp>
#include "hyper_column.h"
#include "configuration_keys.h"
namespace hypernate
{
using std::string;
using std::shared_ptr;
using std::vector;
using std::unordered_set;
class persistent_object;
class hyper_table {
public:
hyper_table(const json& table_config);
string table_name;
vector<shared_ptr<hyper_column>> columns;
inline shared_ptr<hyper_column> find_column_by_column_name(const string& col_name) {
for(auto col : columns) {
if (col->column_name.compare(col_name) == 0) {
return col;
}
}
return nullptr;
}
inline shared_ptr<hyper_column> find_column_by_field_name(const string& field_name) {
for(auto col : columns) {
if (col->field_name.compare(field_name) == 0) {
return col;
}
}
return nullptr;
}
inline shared_ptr<hyper_column> get_primary_column() { return primary_column; }
static const string match_operator(match_mode_t mode, const json& value) {
if (value.is_number()) return "=" + value.dump();
if (value.is_string()) {
switch (mode) {
case match_mode_exact:
return "=" + value.dump();
case match_mode_begin:
return " LIKE '" + value.get<string>() + "%'";
case match_mode_end:
return " LIKE '%" + value.get<string>() + "'";
case match_mode_any:
return " LIKE '%" + value.get<string>() + "%'";
}
}
return "";
}
private:
shared_ptr<hyper_column> primary_column;
};
}
#endif //HYPERNATE_TABLE_H