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 pathstorage_impl.h
74 lines (64 loc) · 2.71 KB
/
storage_impl.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
#pragma once
#include <string> // std::string
#include "functional/cxx_universal.h" // ::nullptr_t
#include "functional/static_magic.h"
#include "tuple_helper/tuple_filter.h"
#include "tuple_helper/tuple_iteration.h"
#include "type_traits.h"
#include "select_constraints.h"
#include "storage_lookup.h"
// interface functions
namespace sqlite_orm {
namespace internal {
template<class DBOs>
using tables_index_sequence = filter_tuple_sequence_t<DBOs, is_table>;
template<class DBOs, satisfies<is_db_objects, DBOs> = true>
int foreign_keys_count(const DBOs& dbObjects) {
int res = 0;
iterate_tuple<true>(dbObjects, tables_index_sequence<DBOs>{}, [&res](const auto& table) {
res += table.foreign_keys_count();
});
return res;
}
template<class Lookup, class DBOs, satisfies<is_db_objects, DBOs>>
auto lookup_table(const DBOs& dbObjects) {
return static_if<is_mapped_v<DBOs, Lookup>>(
[](const auto& dbObjects) {
return &pick_table<Lookup>(dbObjects);
},
empty_callable<nullptr_t>())(dbObjects);
}
template<class Lookup, class DBOs, satisfies<is_db_objects, DBOs>>
decltype(auto) lookup_table_name(const DBOs& dbObjects) {
return static_if<is_mapped_v<DBOs, Lookup>>(
[](const auto& dbObjects) -> const std::string& {
return pick_table<Lookup>(dbObjects).name;
},
empty_callable<std::string>())(dbObjects);
}
/**
* Find column name by its type and member pointer.
*/
template<class O, class F, class DBOs, satisfies<is_db_objects, DBOs> = true>
const std::string* find_column_name(const DBOs& dbObjects, F O::*field) {
return pick_table<O>(dbObjects).find_column_name(field);
}
/**
* Materialize column pointer:
* 1. by explicit object type and member pointer.
*/
template<class O, class F, class DBOs, satisfies<is_db_objects, DBOs> = true>
constexpr decltype(auto) materialize_column_pointer(const DBOs&, const column_pointer<O, F>& cp) {
return cp.field;
}
/**
* Find column name by:
* 1. by explicit object type and member pointer.
*/
template<class O, class F, class DBOs, satisfies<is_db_objects, DBOs> = true>
const std::string* find_column_name(const DBOs& dbObjects, const column_pointer<O, F>& cp) {
auto field = materialize_column_pointer(dbObjects, cp);
return pick_table<O>(dbObjects).find_column_name(field);
}
}
}