This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from fnc12/sqlite_orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpression.h
82 lines (66 loc) · 2.32 KB
/
expression.h
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
#pragma once
#include <tuple>
#include <utility> // std::move, std::forward
#include "functional/cxx_optional.h"
#include "functional/cxx_universal.h"
#include "operators.h"
namespace sqlite_orm {
namespace internal {
template<class L, class R>
struct and_condition_t;
template<class L, class R>
struct or_condition_t;
/**
* Is not an operator but a result of c(...) function. Has operator= overloaded which returns assign_t
*/
template<class T>
struct expression_t : condition_t {
T value;
expression_t(T value_) : value(std::move(value_)) {}
template<class R>
assign_t<T, R> operator=(R r) const {
return {this->value, std::move(r)};
}
assign_t<T, nullptr_t> operator=(nullptr_t) const {
return {this->value, nullptr};
}
#ifdef SQLITE_ORM_OPTIONAL_SUPPORTED
assign_t<T, std::nullopt_t> operator=(std::nullopt_t) const {
return {this->value, std::nullopt};
}
#endif
template<class... Args>
in_t<T, Args...> in(Args... args) const {
return {this->value, std::make_tuple(std::forward<Args>(args)...), false};
}
template<class... Args>
in_t<T, Args...> not_in(Args... args) const {
return {this->value, std::make_tuple(std::forward<Args>(args)...), true};
}
template<class R>
and_condition_t<T, R> and_(R right) const {
return {this->value, std::move(right)};
}
template<class R>
or_condition_t<T, R> or_(R right) const {
return {this->value, std::move(right)};
}
};
template<class T>
T get_from_expression(T value) {
return std::move(value);
}
template<class T>
T get_from_expression(expression_t<T> expression) {
return std::move(expression.value);
}
}
/**
* Public interface for syntax sugar for columns. Example: `where(c(&User::id) == 5)` or
* `storage.update(set(c(&User::name) = "Dua Lipa"));
*/
template<class T>
internal::expression_t<T> c(T value) {
return {std::move(value)};
}
}