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 pathtable_name_collector.h
97 lines (74 loc) · 3.24 KB
/
table_name_collector.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include <set> // std::set
#include <string> // std::string
#include <utility> // std::pair, std::move
#include "functional/cxx_type_traits_polyfill.h"
#include "type_traits.h"
#include "mapped_type_proxy.h"
#include "select_constraints.h"
#include "alias.h"
#include "core_functions.h"
#include "storage_lookup.h"
namespace sqlite_orm {
namespace internal {
struct table_name_collector_base {
using table_name_set = std::set<std::pair<std::string, std::string>>;
table_name_set table_names;
};
template<class DBOs>
struct table_name_collector : table_name_collector_base {
using db_objects_type = DBOs;
const db_objects_type& db_objects;
table_name_collector() = default;
table_name_collector(const db_objects_type& dbObjects) : db_objects{dbObjects} {}
template<class T>
void operator()(const T&) const {}
template<class F, class O>
void operator()(F O::*) {
this->table_names.emplace(lookup_table_name<O>(this->db_objects), "");
}
template<class T, class F>
void operator()(const column_pointer<T, F>&) {
this->table_names.emplace(lookup_table_name<T>(this->db_objects), "");
}
template<class A, class C>
void operator()(const alias_column_t<A, C>&) {
// note: instead of accessing the column, we are interested in the type the column is aliased into
auto tableName = lookup_table_name<mapped_type_proxy_t<A>>(this->db_objects);
this->table_names.emplace(std::move(tableName), alias_extractor<A>::as_alias());
}
template<class T>
void operator()(const count_asterisk_t<T>&) {
auto tableName = lookup_table_name<T>(this->db_objects);
if(!tableName.empty()) {
this->table_names.emplace(std::move(tableName), "");
}
}
template<class T>
void operator()(const asterisk_t<T>&) {
auto tableName = lookup_table_name<mapped_type_proxy_t<T>>(this->db_objects);
table_names.emplace(std::move(tableName), alias_extractor<T>::as_alias());
}
template<class T>
void operator()(const object_t<T>&) {
this->table_names.emplace(lookup_table_name<T>(this->db_objects), "");
}
template<class T>
void operator()(const table_rowid_t<T>&) {
this->table_names.emplace(lookup_table_name<T>(this->db_objects), "");
}
template<class T>
void operator()(const table_oid_t<T>&) {
this->table_names.emplace(lookup_table_name<T>(this->db_objects), "");
}
template<class T>
void operator()(const table__rowid_t<T>&) {
this->table_names.emplace(lookup_table_name<T>(this->db_objects), "");
}
};
template<class DBOs, satisfies<is_db_objects, DBOs> = true>
table_name_collector<DBOs> make_table_name_collector(const DBOs& dbObjects) {
return {dbObjects};
}
}
}