-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.hpp
91 lines (74 loc) · 2.07 KB
/
select.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
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
81
82
83
84
85
86
87
88
89
90
91
#ifndef _SQL_SELECT_HPP
#define _SQL_SELECT_HPP
/**
* Copyright 2015 Maxim Musolov
* This code distribute under private license
*/
#include <string>
#include <type_traits>
#include <query-freaks/sql_base.hpp>
namespace sql {
/** define sql::field */
template <class Entry>
struct field
{
public:
field() {}
template <class ...Args>
std::string operator()(binder<Args...>& b) {
return Entry()(b);
}
std::string operator()() {
return Entry()();
}
};
/** define sql::select */
template <class Fields, class From, class Where = none, class GroupBy = none, class Having = none, class OrderBy = none>
struct _select
{
public:
_select() {}
/** implement select directive */
template <class ...Args>
std::string operator()(binder<Args...>& b) {
return
std::string("SELECT ") +
//helper::impl_select_part<0,Fields...>()(b) +
Fields()(b) + std::string(" ") +
From()(b) +
(std::is_same<Where,none>::value ?
std::string("") :
Where()(b) +
(std::is_same<GroupBy,none>::value ?
std::string("") :
GroupBy()(b) +
(std::is_same<Having,none>::value ?
std::string("") :
Having()(b)))) +
(std::is_same<OrderBy,none>::value ?
std::string("") :
OrderBy()(b));
}
/** expression without query parameters */
std::string operator()() {
return
std::string("SELECT ") +
//helper::impl_select_part<0,Fields...>()() +
Fields()() + std::string(" ") +
From()() +
(std::is_same<Where,none>::value ?
std::string("") :
Where()() +
(std::is_same<GroupBy,none>::value ?
std::string("") :
GroupBy()() +
(std::is_same<Having,none>::value ?
std::string("") :
Having()()))) +
(std::is_same<OrderBy,none>::value ?
std::string("") :
OrderBy()());
}
};
};
#endif