89 std::string table_name = get_table_name<0>();
92 std::string column_list;
93 std::vector<std::string> column_names;
96 (append_column_info<ColumnPtrs>(column_list, column_names, column_list.empty() ?
"" :
", "),
100 std::string index_name = table_name +
"_";
101 for (
size_t i = 0; i < column_names.size(); ++i) {
102 index_name += column_names[i];
103 if (i < column_names.size() - 1) {
107 index_name +=
"_idx";
110 std::string result =
"CREATE ";
112 result +=
"INDEX " + index_name +
" ON ";
113 result += table_name +
" (" + column_list +
")";
123 std::string get_table_name()
const {
124 if constexpr (I <
sizeof...(ColumnPtrs)) {
125 using first_col_ptr_t = std::tuple_element_t<I, std::tuple<
decltype(ColumnPtrs)...>>;
127 typename std::remove_reference_t<typename table_for_column<first_col_ptr_t>::type>;
128 return std::string(table_t::table_name);
131 static_assert(I <
sizeof...(ColumnPtrs),
132 "Invalid index template parameters: no columns provided");
137 template <
typename T>
138 struct table_for_column;
140 template <
typename C,
typename T>
141 struct table_for_column<T C::*> {
146 template <auto ColumnPtr>
147 void append_column_info(std::string& column_list, std::vector<std::string>& column_names,
148 const std::string& separator)
const {
149 using col_type =
decltype(ColumnPtr);
150 using column_type =
typename std::remove_reference_t<typename column_type_for<col_type>::type>;
151 std::string column_name = std::string(column_type::name);
154 column_list += separator + column_name;
157 column_names.push_back(column_name);
161 template <
typename T>
162 struct column_type_for;
164 template <
typename C,
typename T>
165 struct column_type_for<T C::*> {