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 pathindexed_column.h
70 lines (55 loc) · 1.91 KB
/
indexed_column.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
#pragma once
#include <string> // std::string
#include <utility> // std::move
#include "functional/cxx_universal.h"
#include "ast/where.h"
namespace sqlite_orm {
namespace internal {
template<class C>
struct indexed_column_t {
using column_type = C;
#ifndef SQLITE_ORM_AGGREGATE_NSDMI_SUPPORTED
indexed_column_t(column_type _column_or_expression) :
column_or_expression(std::move(_column_or_expression)) {}
#endif
column_type column_or_expression;
std::string _collation_name;
int _order = 0; // -1 = desc, 1 = asc, 0 = not specified
indexed_column_t<column_type> collate(std::string name) {
auto res = std::move(*this);
res._collation_name = std::move(name);
return res;
}
indexed_column_t<column_type> asc() {
auto res = std::move(*this);
res._order = 1;
return res;
}
indexed_column_t<column_type> desc() {
auto res = std::move(*this);
res._order = -1;
return res;
}
};
template<class C>
indexed_column_t<C> make_indexed_column(C col) {
return {std::move(col)};
}
template<class C>
where_t<C> make_indexed_column(where_t<C> wher) {
return std::move(wher);
}
template<class C>
indexed_column_t<C> make_indexed_column(indexed_column_t<C> col) {
return std::move(col);
}
}
/**
* Use this function to specify indexed column inside `make_index` function call.
* Example: make_index("index_name", indexed_column(&User::id).asc())
*/
template<class C>
internal::indexed_column_t<C> indexed_column(C column_or_expression) {
return {std::move(column_or_expression)};
}
}