@@ -3371,7 +3371,7 @@ namespace sqlite_orm {
3371
3371
return *this;
3372
3372
}
3373
3373
#ifndef SQLITE_ORM_AGGREGATE_BASES_SUPPORTED
3374
- primary_key_with_autoincrement(primary_key_type primary_key) : primary_key_type{primary_key} {}
3374
+ constexpr primary_key_with_autoincrement(primary_key_type primary_key) : primary_key_type{primary_key} {}
3375
3375
#endif
3376
3376
};
3377
3377
@@ -3382,59 +3382,58 @@ namespace sqlite_orm {
3382
3382
*/
3383
3383
template<class... Cs>
3384
3384
struct primary_key_t : primary_key_base {
3385
- using self = primary_key_t<Cs...>;
3386
3385
using order_by = primary_key_base::order_by;
3387
3386
using columns_tuple = std::tuple<Cs...>;
3388
3387
3389
3388
columns_tuple columns;
3390
3389
3391
- primary_key_t(columns_tuple columns) : columns(std::move(columns)) {}
3390
+ constexpr primary_key_t(columns_tuple columns) : columns(std::move(columns)) {}
3392
3391
3393
- self asc() const {
3392
+ constexpr primary_key_t asc() const {
3394
3393
auto res = *this;
3395
3394
res.options.asc_option = order_by::ascending;
3396
3395
return res;
3397
3396
}
3398
3397
3399
- self desc() const {
3398
+ constexpr primary_key_t desc() const {
3400
3399
auto res = *this;
3401
3400
res.options.asc_option = order_by::descending;
3402
3401
return res;
3403
3402
}
3404
3403
3405
- primary_key_with_autoincrement<self > autoincrement() const {
3404
+ constexpr primary_key_with_autoincrement<primary_key_t > autoincrement() const {
3406
3405
return {*this};
3407
3406
}
3408
3407
3409
- self on_conflict_rollback() const {
3408
+ constexpr primary_key_t on_conflict_rollback() const {
3410
3409
auto res = *this;
3411
3410
res.options.conflict_clause_is_on = true;
3412
3411
res.options.conflict_clause = conflict_clause_t::rollback;
3413
3412
return res;
3414
3413
}
3415
3414
3416
- self on_conflict_abort() const {
3415
+ constexpr primary_key_t on_conflict_abort() const {
3417
3416
auto res = *this;
3418
3417
res.options.conflict_clause_is_on = true;
3419
3418
res.options.conflict_clause = conflict_clause_t::abort;
3420
3419
return res;
3421
3420
}
3422
3421
3423
- self on_conflict_fail() const {
3422
+ constexpr primary_key_t on_conflict_fail() const {
3424
3423
auto res = *this;
3425
3424
res.options.conflict_clause_is_on = true;
3426
3425
res.options.conflict_clause = conflict_clause_t::fail;
3427
3426
return res;
3428
3427
}
3429
3428
3430
- self on_conflict_ignore() const {
3429
+ constexpr primary_key_t on_conflict_ignore() const {
3431
3430
auto res = *this;
3432
3431
res.options.conflict_clause_is_on = true;
3433
3432
res.options.conflict_clause = conflict_clause_t::ignore;
3434
3433
return res;
3435
3434
}
3436
3435
3437
- self on_conflict_replace() const {
3436
+ constexpr primary_key_t on_conflict_replace() const {
3438
3437
auto res = *this;
3439
3438
res.options.conflict_clause_is_on = true;
3440
3439
res.options.conflict_clause = conflict_clause_t::replace;
@@ -3853,7 +3852,7 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
3853
3852
3854
3853
#if SQLITE_VERSION_NUMBER >= 3006019
3855
3854
/**
3856
- * FOREIGN KEY constraint builder function taking one or more fields [member pointer or column pointer] as argument.
3855
+ * Composite FOREIGN KEY constraint builder function taking one or more fields [member pointer or column pointer] as argument.
3857
3856
* Available since SQLite 3.6.19
3858
3857
*/
3859
3858
template<class... Cs>
@@ -3862,7 +3861,7 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
3862
3861
}
3863
3862
3864
3863
/**
3865
- * FOREIGN KEY constraint builder function taking one or more fields from a derived class as a member pointer of a base class as argument.
3864
+ * Composite FOREIGN KEY constraint builder function taking one or more fields from a derived class as a member pointer of a base class as argument.
3866
3865
* Available since SQLite 3.6.19
3867
3866
*/
3868
3867
template<class O, class... Base, class... F>
@@ -3874,7 +3873,7 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
3874
3873
3875
3874
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
3876
3875
/**
3877
- * FOREIGN KEY constraint builder function taking one or more fields from a derived class as a member pointer of a base class as argument.
3876
+ * Composite FOREIGN KEY constraint builder function taking one or more fields from a derived class as a member pointer of a base class as argument.
3878
3877
* Available since SQLite 3.6.19
3879
3878
*/
3880
3879
template<orm_table_reference auto table, class... Base, class... F>
@@ -3954,14 +3953,34 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
3954
3953
* PRIMARY KEY table constraint builder function.
3955
3954
*/
3956
3955
template<class... Cs>
3957
- internal::primary_key_t<Cs...> primary_key(Cs... cs) {
3956
+ constexpr internal::primary_key_t<Cs...> primary_key(Cs... cs) {
3958
3957
return {{std::forward<Cs>(cs)...}};
3959
3958
}
3960
3959
3961
3960
/**
3962
- * PRIMARY KEY column constraint builder function.
3961
+ * Composite PRIMARY KEY table constraint builder function taking one or more fields from a derived class as a member pointer of a base class as argument.
3962
+ */
3963
+ template<class O, class... Base, class... F>
3964
+ constexpr internal::primary_key_t<F O::*...> primary_key(F Base::*... columns) {
3965
+ static_assert(std::conjunction<internal::is_field_of<F Base::*, O>...>::value,
3966
+ "Fields must be from explicitly specified derived class");
3967
+ return {{columns...}};
3968
+ }
3969
+
3970
+ #ifdef SQLITE_ORM_WITH_CPP20_ALIASES
3971
+ /**
3972
+ * Composite PRIMARY KEY table constraint builder function taking one or more fields from a derived class as a member pointer of a base class as argument.
3963
3973
*/
3964
- inline internal::primary_key_t<> primary_key() {
3974
+ template<orm_table_reference auto table, class... Base, class... F>
3975
+ constexpr auto primary_key(F Base::*... columns) {
3976
+ return primary_key<internal::auto_decay_table_ref_t<table>>(columns...);
3977
+ }
3978
+ #endif
3979
+
3980
+ /**
3981
+ * PRIMARY KEY column constraint builder function (used at a single column).
3982
+ */
3983
+ inline constexpr internal::primary_key_t<> primary_key() {
3965
3984
return {{}};
3966
3985
}
3967
3986
@@ -12715,10 +12734,11 @@ namespace sqlite_orm {
12715
12734
using tables_index_sequence = filter_tuple_sequence_t<DBOs, is_table>;
12716
12735
12717
12736
template<class DBOs, satisfies<is_db_objects, DBOs> = true>
12718
- int foreign_keys_count(const DBOs& dbObjects ) {
12737
+ constexpr int foreign_keys_count() {
12719
12738
int res = 0;
12720
- iterate_tuple<true>(dbObjects, tables_index_sequence<DBOs>{}, [&res](const auto& table) {
12721
- res += table.template count_of<is_foreign_key>();
12739
+ iterate_tuple<DBOs>(tables_index_sequence<DBOs>{}, [&res](const auto* dummy) {
12740
+ using table_type = std::remove_pointer_t<decltype(dummy)>;
12741
+ res += table_type::template count_of<is_foreign_key>();
12722
12742
});
12723
12743
return res;
12724
12744
}
@@ -20820,7 +20840,7 @@ namespace sqlite_orm {
20820
20840
ss << " ON CONFLICT " << serialize(statement.options.conflict_clause, context);
20821
20841
}
20822
20842
using columns_tuple = typename statement_type::columns_tuple;
20823
- const size_t columnsCount = std::tuple_size<columns_tuple>::value;
20843
+ constexpr size_t columnsCount = std::tuple_size<columns_tuple>::value;
20824
20844
if (columnsCount) {
20825
20845
ss << "(" << streaming_mapped_columns_expressions(statement.columns, context) << ")";
20826
20846
}
@@ -22638,7 +22658,7 @@ namespace sqlite_orm {
22638
22658
storage_base{std::move(filename),
22639
22659
storage_opt_or_default<connection_control>(options),
22640
22660
storage_opt_or_default<on_open_spec>(options),
22641
- foreign_keys_count(dbObjects )},
22661
+ foreign_keys_count<db_objects_type>( )},
22642
22662
db_objects{std::move(dbObjects)} {}
22643
22663
22644
22664
storage_t(const storage_t&) = default;
0 commit comments