Skip to content

Commit f7b5647

Browse files
committed
Merge remote-tracking branch 'origin/prefix-cleanup' into prefix-cleanup
2 parents b4c8ea6 + be1b899 commit f7b5647

File tree

4 files changed

+104
-44
lines changed

4 files changed

+104
-44
lines changed

dev/constraints.h

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <system_error> // std::system_error
44
#include <ostream> // std::ostream
55
#include <string> // std::string
6-
#include <tuple> // std::tuple, std::make_tuple
6+
#include <tuple> // std::tuple
77
#include <type_traits> // std::is_base_of, std::false_type, std::true_type
88

99
#include "functional/cxx_universal.h"
@@ -356,7 +356,7 @@ namespace sqlite_orm {
356356

357357
template<class... Rs>
358358
foreign_key_t<std::tuple<Cs...>, std::tuple<Rs...>> references(Rs... refs) {
359-
return {std::move(this->columns), std::make_tuple(std::forward<Rs>(refs)...)};
359+
return {std::move(this->columns), {std::forward<Rs>(refs)...}};
360360
}
361361
};
362362
#endif
@@ -476,17 +476,16 @@ namespace sqlite_orm {
476476
};
477477

478478
template<class T>
479-
using is_constraint = mpl::invoke_t<mpl::disjunction<check_if<is_primary_key>,
480-
check_if<is_foreign_key>,
481-
check_if_is_type<null_t>,
482-
check_if_is_type<not_null_t>,
483-
check_if_is_type<unindexed_t>,
484-
check_if_is_template<unique_t>,
485-
check_if_is_template<default_t>,
486-
check_if_is_template<check_t>,
487-
check_if_is_type<collate_constraint_t>,
488-
check_if<is_generated_always>>,
489-
T>;
479+
using is_column_constraint = mpl::invoke_t<mpl::disjunction<check_if<is_primary_key>,
480+
check_if_is_type<null_t>,
481+
check_if_is_type<not_null_t>,
482+
check_if_is_template<unique_t>,
483+
check_if_is_template<default_t>,
484+
check_if_is_template<check_t>,
485+
check_if_is_type<collate_constraint_t>,
486+
check_if<is_generated_always>,
487+
check_if_is_type<unindexed_t>>,
488+
T>;
490489
}
491490

492491
#if SQLITE_VERSION_NUMBER >= 3031000
@@ -500,32 +499,35 @@ namespace sqlite_orm {
500499
return {std::move(expression), false, internal::basic_generated_always::storage_type::not_specified};
501500
}
502501
#endif
503-
#if SQLITE_VERSION_NUMBER >= 3006019
504502

503+
#if SQLITE_VERSION_NUMBER >= 3006019
505504
/**
506505
* FOREIGN KEY constraint construction function that takes member pointer as argument
507506
* Available in SQLite 3.6.19 or higher
508507
*/
509508
template<class... Cs>
510509
internal::foreign_key_intermediate_t<Cs...> foreign_key(Cs... columns) {
511-
return {std::make_tuple(std::forward<Cs>(columns)...)};
510+
return {{std::forward<Cs>(columns)...}};
512511
}
513512
#endif
514513

515514
/**
516-
* UNIQUE constraint builder function.
515+
* UNIQUE table constraint builder function.
517516
*/
518517
template<class... Args>
519518
internal::unique_t<Args...> unique(Args... args) {
520519
return {{std::forward<Args>(args)...}};
521520
}
522521

522+
/**
523+
* UNIQUE column constraint builder function.
524+
*/
523525
inline internal::unique_t<> unique() {
524526
return {{}};
525527
}
526528

527529
/**
528-
* UNINDEXED constraint builder function. Used in FTS virtual tables.
530+
* UNINDEXED column constraint builder function. Used in FTS virtual tables.
529531
*
530532
* https://www.sqlite.org/fts5.html#the_unindexed_column_option
531533
*/
@@ -534,7 +536,7 @@ namespace sqlite_orm {
534536
}
535537

536538
/**
537-
* prefix=N constraint builder function. Used in FTS virtual tables.
539+
* prefix=N table constraint builder function. Used in FTS virtual tables.
538540
*
539541
* https://www.sqlite.org/fts5.html#prefix_indexes
540542
*/
@@ -543,11 +545,17 @@ namespace sqlite_orm {
543545
return {std::move(value)};
544546
}
545547

548+
/**
549+
* PRIMARY KEY table constraint builder function.
550+
*/
546551
template<class... Cs>
547552
internal::primary_key_t<Cs...> primary_key(Cs... cs) {
548-
return {std::make_tuple(std::forward<Cs>(cs)...)};
553+
return {{std::forward<Cs>(cs)...}};
549554
}
550555

556+
/**
557+
* PRIMARY KEY column constraint builder function.
558+
*/
551559
inline internal::primary_key_t<> primary_key() {
552560
return {{}};
553561
}

dev/schema/column.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace sqlite_orm {
149149
template<class M, class... Op, internal::satisfies<std::is_member_object_pointer, M> = true>
150150
internal::column_t<M, internal::empty_setter, Op...>
151151
make_column(std::string name, M memberPointer, Op... constraints) {
152-
static_assert(polyfill::conjunction_v<internal::is_constraint<Op>...>, "Incorrect constraints pack");
152+
static_assert(polyfill::conjunction_v<internal::is_column_constraint<Op>...>, "Incorrect constraints pack");
153153

154154
// attention: do not use `std::make_tuple()` for constructing the tuple member `[[no_unique_address]] column_constraints::constraints`,
155155
// as this will lead to UB with Clang on MinGW!
@@ -168,7 +168,7 @@ namespace sqlite_orm {
168168
internal::column_t<G, S, Op...> make_column(std::string name, S setter, G getter, Op... constraints) {
169169
static_assert(std::is_same<internal::setter_field_type_t<S>, internal::getter_field_type_t<G>>::value,
170170
"Getter and setter must get and set same data type");
171-
static_assert(polyfill::conjunction_v<internal::is_constraint<Op>...>, "Incorrect constraints pack");
171+
static_assert(polyfill::conjunction_v<internal::is_column_constraint<Op>...>, "Incorrect constraints pack");
172172

173173
// attention: do not use `std::make_tuple()` for constructing the tuple member `[[no_unique_address]] column_constraints::constraints`,
174174
// as this will lead to UB with Clang on MinGW!
@@ -187,7 +187,7 @@ namespace sqlite_orm {
187187
internal::column_t<G, S, Op...> make_column(std::string name, G getter, S setter, Op... constraints) {
188188
static_assert(std::is_same<internal::setter_field_type_t<S>, internal::getter_field_type_t<G>>::value,
189189
"Getter and setter must get and set same data type");
190-
static_assert(polyfill::conjunction_v<internal::is_constraint<Op>...>, "Incorrect constraints pack");
190+
static_assert(polyfill::conjunction_v<internal::is_column_constraint<Op>...>, "Incorrect constraints pack");
191191

192192
// attention: do not use `std::make_tuple()` for constructing the tuple member `[[no_unique_address]] column_constraints::constraints`,
193193
// as this will lead to UB with Clang on MinGW!

dev/schema/table.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ namespace sqlite_orm {
2828

2929
namespace internal {
3030

31+
template<class T>
32+
using is_table_element_or_constraint = mpl::invoke_t<mpl::disjunction<check_if<is_column>,
33+
check_if<is_primary_key>,
34+
check_if<is_foreign_key>,
35+
check_if_is_template<index_t>,
36+
check_if_is_template<unique_t>,
37+
check_if_is_template<check_t>,
38+
check_if_is_template<prefix_t>>,
39+
T>;
40+
3141
#ifdef SQLITE_ORM_WITH_CTE
3242
/**
3343
* A subselect mapper's CTE moniker, void otherwise.
@@ -402,11 +412,17 @@ namespace sqlite_orm {
402412

403413
template<class... Cs, class T = typename std::tuple_element_t<0, std::tuple<Cs...>>::object_type>
404414
internal::using_fts5_t<T, Cs...> using_fts5(Cs... columns) {
415+
static_assert(polyfill::conjunction_v<internal::is_table_element_or_constraint<Cs>...>,
416+
"Incorrect table elements or constraints");
417+
405418
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(return {std::make_tuple(std::forward<Cs>(columns)...)});
406419
}
407420

408421
template<class T, class... Cs>
409422
internal::using_fts5_t<T, Cs...> using_fts5(Cs... columns) {
423+
static_assert(polyfill::conjunction_v<internal::is_table_element_or_constraint<Cs>...>,
424+
"Incorrect table elements or constraints");
425+
410426
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(return {std::make_tuple(std::forward<Cs>(columns)...)});
411427
}
412428

@@ -417,6 +433,9 @@ namespace sqlite_orm {
417433
*/
418434
template<class... Cs, class T = typename std::tuple_element_t<0, std::tuple<Cs...>>::object_type>
419435
internal::table_t<T, false, Cs...> make_table(std::string name, Cs... args) {
436+
static_assert(polyfill::conjunction_v<internal::is_table_element_or_constraint<Cs>...>,
437+
"Incorrect table elements or constraints");
438+
420439
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(
421440
return {std::move(name), std::make_tuple<Cs...>(std::forward<Cs>(args)...)});
422441
}
@@ -428,6 +447,9 @@ namespace sqlite_orm {
428447
*/
429448
template<class T, class... Cs>
430449
internal::table_t<T, false, Cs...> make_table(std::string name, Cs... args) {
450+
static_assert(polyfill::conjunction_v<internal::is_table_element_or_constraint<Cs>...>,
451+
"Incorrect table elements or constraints");
452+
431453
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(
432454
return {std::move(name), std::make_tuple<Cs...>(std::forward<Cs>(args)...)});
433455
}

include/sqlite_orm/sqlite_orm.h

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ namespace sqlite_orm {
841841
#include <system_error> // std::system_error
842842
#include <ostream> // std::ostream
843843
#include <string> // std::string
844-
#include <tuple> // std::tuple, std::make_tuple
844+
#include <tuple> // std::tuple
845845
#include <type_traits> // std::is_base_of, std::false_type, std::true_type
846846

847847
// #include "functional/cxx_universal.h"
@@ -2016,7 +2016,7 @@ namespace sqlite_orm {
20162016

20172017
template<class... Rs>
20182018
foreign_key_t<std::tuple<Cs...>, std::tuple<Rs...>> references(Rs... refs) {
2019-
return {std::move(this->columns), std::make_tuple(std::forward<Rs>(refs)...)};
2019+
return {std::move(this->columns), {std::forward<Rs>(refs)...}};
20202020
}
20212021
};
20222022
#endif
@@ -2136,17 +2136,16 @@ namespace sqlite_orm {
21362136
};
21372137

21382138
template<class T>
2139-
using is_constraint = mpl::invoke_t<mpl::disjunction<check_if<is_primary_key>,
2140-
check_if<is_foreign_key>,
2141-
check_if_is_type<null_t>,
2142-
check_if_is_type<not_null_t>,
2143-
check_if_is_type<unindexed_t>,
2144-
check_if_is_template<unique_t>,
2145-
check_if_is_template<default_t>,
2146-
check_if_is_template<check_t>,
2147-
check_if_is_type<collate_constraint_t>,
2148-
check_if<is_generated_always>>,
2149-
T>;
2139+
using is_column_constraint = mpl::invoke_t<mpl::disjunction<check_if<is_primary_key>,
2140+
check_if_is_type<null_t>,
2141+
check_if_is_type<not_null_t>,
2142+
check_if_is_template<unique_t>,
2143+
check_if_is_template<default_t>,
2144+
check_if_is_template<check_t>,
2145+
check_if_is_type<collate_constraint_t>,
2146+
check_if<is_generated_always>,
2147+
check_if_is_type<unindexed_t>>,
2148+
T>;
21502149
}
21512150

21522151
#if SQLITE_VERSION_NUMBER >= 3031000
@@ -2160,32 +2159,35 @@ namespace sqlite_orm {
21602159
return {std::move(expression), false, internal::basic_generated_always::storage_type::not_specified};
21612160
}
21622161
#endif
2163-
#if SQLITE_VERSION_NUMBER >= 3006019
21642162

2163+
#if SQLITE_VERSION_NUMBER >= 3006019
21652164
/**
21662165
* FOREIGN KEY constraint construction function that takes member pointer as argument
21672166
* Available in SQLite 3.6.19 or higher
21682167
*/
21692168
template<class... Cs>
21702169
internal::foreign_key_intermediate_t<Cs...> foreign_key(Cs... columns) {
2171-
return {std::make_tuple(std::forward<Cs>(columns)...)};
2170+
return {{std::forward<Cs>(columns)...}};
21722171
}
21732172
#endif
21742173

21752174
/**
2176-
* UNIQUE constraint builder function.
2175+
* UNIQUE table constraint builder function.
21772176
*/
21782177
template<class... Args>
21792178
internal::unique_t<Args...> unique(Args... args) {
21802179
return {{std::forward<Args>(args)...}};
21812180
}
21822181

2182+
/**
2183+
* UNIQUE column constraint builder function.
2184+
*/
21832185
inline internal::unique_t<> unique() {
21842186
return {{}};
21852187
}
21862188

21872189
/**
2188-
* UNINDEXED constraint builder function. Used in FTS virtual tables.
2190+
* UNINDEXED column constraint builder function. Used in FTS virtual tables.
21892191
*
21902192
* https://www.sqlite.org/fts5.html#the_unindexed_column_option
21912193
*/
@@ -2194,7 +2196,7 @@ namespace sqlite_orm {
21942196
}
21952197

21962198
/**
2197-
* prefix=N constraint builder function. Used in FTS virtual tables.
2199+
* prefix=N table constraint builder function. Used in FTS virtual tables.
21982200
*
21992201
* https://www.sqlite.org/fts5.html#prefix_indexes
22002202
*/
@@ -2203,11 +2205,17 @@ namespace sqlite_orm {
22032205
return {std::move(value)};
22042206
}
22052207

2208+
/**
2209+
* PRIMARY KEY table constraint builder function.
2210+
*/
22062211
template<class... Cs>
22072212
internal::primary_key_t<Cs...> primary_key(Cs... cs) {
2208-
return {std::make_tuple(std::forward<Cs>(cs)...)};
2213+
return {{std::forward<Cs>(cs)...}};
22092214
}
22102215

2216+
/**
2217+
* PRIMARY KEY column constraint builder function.
2218+
*/
22112219
inline internal::primary_key_t<> primary_key() {
22122220
return {{}};
22132221
}
@@ -2985,7 +2993,7 @@ namespace sqlite_orm {
29852993
template<class M, class... Op, internal::satisfies<std::is_member_object_pointer, M> = true>
29862994
internal::column_t<M, internal::empty_setter, Op...>
29872995
make_column(std::string name, M memberPointer, Op... constraints) {
2988-
static_assert(polyfill::conjunction_v<internal::is_constraint<Op>...>, "Incorrect constraints pack");
2996+
static_assert(polyfill::conjunction_v<internal::is_column_constraint<Op>...>, "Incorrect constraints pack");
29892997

29902998
// attention: do not use `std::make_tuple()` for constructing the tuple member `[[no_unique_address]] column_constraints::constraints`,
29912999
// as this will lead to UB with Clang on MinGW!
@@ -3004,7 +3012,7 @@ namespace sqlite_orm {
30043012
internal::column_t<G, S, Op...> make_column(std::string name, S setter, G getter, Op... constraints) {
30053013
static_assert(std::is_same<internal::setter_field_type_t<S>, internal::getter_field_type_t<G>>::value,
30063014
"Getter and setter must get and set same data type");
3007-
static_assert(polyfill::conjunction_v<internal::is_constraint<Op>...>, "Incorrect constraints pack");
3015+
static_assert(polyfill::conjunction_v<internal::is_column_constraint<Op>...>, "Incorrect constraints pack");
30083016

30093017
// attention: do not use `std::make_tuple()` for constructing the tuple member `[[no_unique_address]] column_constraints::constraints`,
30103018
// as this will lead to UB with Clang on MinGW!
@@ -3023,7 +3031,7 @@ namespace sqlite_orm {
30233031
internal::column_t<G, S, Op...> make_column(std::string name, G getter, S setter, Op... constraints) {
30243032
static_assert(std::is_same<internal::setter_field_type_t<S>, internal::getter_field_type_t<G>>::value,
30253033
"Getter and setter must get and set same data type");
3026-
static_assert(polyfill::conjunction_v<internal::is_constraint<Op>...>, "Incorrect constraints pack");
3034+
static_assert(polyfill::conjunction_v<internal::is_column_constraint<Op>...>, "Incorrect constraints pack");
30273035

30283036
// attention: do not use `std::make_tuple()` for constructing the tuple member `[[no_unique_address]] column_constraints::constraints`,
30293037
// as this will lead to UB with Clang on MinGW!
@@ -11260,6 +11268,16 @@ namespace sqlite_orm {
1126011268

1126111269
namespace internal {
1126211270

11271+
template<class T>
11272+
using is_table_element_or_constraint = mpl::invoke_t<mpl::disjunction<check_if<is_column>,
11273+
check_if<is_primary_key>,
11274+
check_if<is_foreign_key>,
11275+
check_if_is_template<index_t>,
11276+
check_if_is_template<unique_t>,
11277+
check_if_is_template<check_t>,
11278+
check_if_is_template<prefix_t>>,
11279+
T>;
11280+
1126311281
#ifdef SQLITE_ORM_WITH_CTE
1126411282
/**
1126511283
* A subselect mapper's CTE moniker, void otherwise.
@@ -11634,11 +11652,17 @@ namespace sqlite_orm {
1163411652

1163511653
template<class... Cs, class T = typename std::tuple_element_t<0, std::tuple<Cs...>>::object_type>
1163611654
internal::using_fts5_t<T, Cs...> using_fts5(Cs... columns) {
11655+
static_assert(polyfill::conjunction_v<internal::is_table_element_or_constraint<Cs>...>,
11656+
"Incorrect table elements or constraints");
11657+
1163711658
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(return {std::make_tuple(std::forward<Cs>(columns)...)});
1163811659
}
1163911660

1164011661
template<class T, class... Cs>
1164111662
internal::using_fts5_t<T, Cs...> using_fts5(Cs... columns) {
11663+
static_assert(polyfill::conjunction_v<internal::is_table_element_or_constraint<Cs>...>,
11664+
"Incorrect table elements or constraints");
11665+
1164211666
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(return {std::make_tuple(std::forward<Cs>(columns)...)});
1164311667
}
1164411668

@@ -11649,6 +11673,9 @@ namespace sqlite_orm {
1164911673
*/
1165011674
template<class... Cs, class T = typename std::tuple_element_t<0, std::tuple<Cs...>>::object_type>
1165111675
internal::table_t<T, false, Cs...> make_table(std::string name, Cs... args) {
11676+
static_assert(polyfill::conjunction_v<internal::is_table_element_or_constraint<Cs>...>,
11677+
"Incorrect table elements or constraints");
11678+
1165211679
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(
1165311680
return {std::move(name), std::make_tuple<Cs...>(std::forward<Cs>(args)...)});
1165411681
}
@@ -11660,6 +11687,9 @@ namespace sqlite_orm {
1166011687
*/
1166111688
template<class T, class... Cs>
1166211689
internal::table_t<T, false, Cs...> make_table(std::string name, Cs... args) {
11690+
static_assert(polyfill::conjunction_v<internal::is_table_element_or_constraint<Cs>...>,
11691+
"Incorrect table elements or constraints");
11692+
1166311693
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(
1166411694
return {std::move(name), std::make_tuple<Cs...>(std::forward<Cs>(args)...)});
1166511695
}

0 commit comments

Comments
 (0)