-
Notifications
You must be signed in to change notification settings - Fork 21
/
sweetql.hpp
86 lines (68 loc) · 1.7 KB
/
sweetql.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
// LGPL 3 or higher Robert Burner Schadek rburners@gmail.com
#pragma once
#include <algorithm>
#include <functional>
#include <vector>
#include <stdexcept>
#include <sstream>
#include <iterator>
#include <string>
#include <memory>
#include "sweetqlimpl/types.hpp"
#include "sweetqlimpl/sqliteimpl.hpp"
template<typename Impl>
class SweetQL {
public:
inline SweetQL(Impl& i) : impl(i) {
}
inline void beginTransaction() {
this->impl.beginTransaction();
}
inline void endTransaction() {
this->impl.endTransaction();
}
template<typename S>
bool insert(S& t) {
return this->impl. template insert<S>(t);
}
template<typename S, typename It>
bool insert(It be, It en) {
return this->impl. template insert<S>(be, en);
}
template<typename S>
void createTable(bool ifNotExists=true) {
this->impl. template createTable<S>(ifNotExists);
}
template<typename S>
void dropTable(bool ifExists=true) {
this->impl. template dropTable<S>(ifExists);
}
template<typename S>
void remove(S& s) {
this->impl.remove(s);
}
template<typename S>
std::pair<typename Impl:: template Iterator<S>,
typename Impl:: template Iterator<S>> select(const std::string& where = "")
{
return this->impl. template select<S>(where);
}
template<typename S>
S selectOne(bool& wasSet, const std::string& where = "") {
auto its = this->select<S>(where);
if(its.first == its.second) {
wasSet = false;
return S();
}
wasSet = true;
return *its.first;
}
template<typename S, typename T, typename R>
std::pair<typename Impl:: template Iterator<S>, typename Impl:: template Iterator<S>> join(
const std::string& where = "")
{
return this->impl. template join<S,T,R>(where);
}
private:
Impl& impl;
};