@@ -12704,17 +12704,15 @@ namespace sqlite_orm {
12704
12704
constexpr decltype(auto) materialize_column_pointer(const DBOs&,
12705
12705
const column_pointer<Moniker, alias_holder<ColAlias>>&) {
12706
12706
using table_type = storage_pick_table_t<Moniker, DBOs>;
12707
- using cte_mapper_type = cte_mapper_type_t<table_type>;
12707
+ using cte_colrefs_tuple = typename cte_mapper_type_t<table_type>::final_colrefs_tuple;
12708
+ using cte_fields_type = typename cte_mapper_type_t<table_type>::fields_type;
12708
12709
12709
12710
// lookup ColAlias in the final column references
12710
- using colalias_index =
12711
- find_tuple_type<typename cte_mapper_type::final_colrefs_tuple, alias_holder<ColAlias>>;
12712
- static_assert(colalias_index::value < std::tuple_size_v<typename cte_mapper_type::final_colrefs_tuple>,
12711
+ using colalias_index = find_tuple_type<cte_colrefs_tuple, alias_holder<ColAlias>>;
12712
+ static_assert(colalias_index::value < std::tuple_size_v<cte_colrefs_tuple>,
12713
12713
"No such column mapped into the CTE.");
12714
12714
12715
- return &aliased_field<
12716
- ColAlias,
12717
- std::tuple_element_t<colalias_index::value, typename cte_mapper_type::fields_type>>::field;
12715
+ return &aliased_field<ColAlias, std::tuple_element_t<colalias_index::value, cte_fields_type>>::field;
12718
12716
}
12719
12717
#endif
12720
12718
@@ -12738,14 +12736,13 @@ namespace sqlite_orm {
12738
12736
constexpr decltype(auto) find_column_name(const DBOs& dboObjects,
12739
12737
const column_pointer<Moniker, alias_holder<ColAlias>>&) {
12740
12738
using table_type = storage_pick_table_t<Moniker, DBOs>;
12741
- using cte_mapper_type = cte_mapper_type_t<table_type>;
12739
+ using cte_colrefs_tuple = typename cte_mapper_type_t<table_type>::final_colrefs_tuple ;
12742
12740
using column_index_sequence = filter_tuple_sequence_t<elements_type_t<table_type>, is_column>;
12743
12741
12744
12742
// note: even though the columns contain the [`aliased_field<>::*`] we perform the lookup using the column references.
12745
12743
// lookup ColAlias in the final column references
12746
- using colalias_index =
12747
- find_tuple_type<typename cte_mapper_type::final_colrefs_tuple, alias_holder<ColAlias>>;
12748
- static_assert(colalias_index::value < std::tuple_size_v<typename cte_mapper_type::final_colrefs_tuple>,
12744
+ using colalias_index = find_tuple_type<cte_colrefs_tuple, alias_holder<ColAlias>>;
12745
+ static_assert(colalias_index::value < std::tuple_size_v<cte_colrefs_tuple>,
12749
12746
"No such column mapped into the CTE.");
12750
12747
12751
12748
// note: we could "materialize" the alias to an `aliased_field<>::*` and use the regular `table_t<>::find_column_name()` mechanism;
@@ -13981,15 +13978,15 @@ namespace sqlite_orm {
13981
13978
std::binary_semaphore& sync;
13982
13979
};
13983
13980
13984
- connection_holder(std::string filename, bool openedForeverHint, std::function<void(sqlite3*)> onAfterOpen ) :
13985
- _openedForeverHint{openedForeverHint}, _onAfterOpen {std::move(onAfterOpen )},
13986
- filename(std::move(filename)) { }
13981
+ connection_holder(std::string filename, bool openedForeverHint, std::function<void(sqlite3*)> didOpenDb ) :
13982
+ _openedForeverHint{openedForeverHint}, _didOpenDb {std::move(didOpenDb )}, filename(std::move(filename)) {
13983
+ }
13987
13984
13988
13985
connection_holder(const connection_holder&) = delete;
13989
13986
13990
- connection_holder(const connection_holder& other, std::function<void(sqlite3*)> onAfterOpen ) :
13991
- filename {other.filename }, _openedForeverHint{other._openedForeverHint },
13992
- _onAfterOpen{std::move(onAfterOpen) } {}
13987
+ connection_holder(const connection_holder& other, std::function<void(sqlite3*)> didOpenDb ) :
13988
+ _openedForeverHint {other._openedForeverHint }, _didOpenDb{std::move(didOpenDb) },
13989
+ filename{other.filename } {}
13993
13990
13994
13991
void retain() {
13995
13992
const maybe_lock maybeLock{_sync, !_openedForeverHint};
@@ -14011,8 +14008,8 @@ namespace sqlite_orm {
14011
14008
throw_translated_sqlite_error(this->db);
14012
14009
}
14013
14010
14014
- if (_onAfterOpen ) {
14015
- _onAfterOpen (this->db);
14011
+ if (_didOpenDb ) {
14012
+ _didOpenDb (this->db);
14016
14013
}
14017
14014
}
14018
14015
@@ -14032,7 +14029,7 @@ namespace sqlite_orm {
14032
14029
14033
14030
// last one closes the connection.
14034
14031
14035
- if (int rc = sqlite3_close (this->db); rc != SQLITE_OK) [[unlikely]] {
14032
+ if (int rc = sqlite3_close_v2 (this->db); rc != SQLITE_OK) [[unlikely]] {
14036
14033
throw_translated_sqlite_error(this->db);
14037
14034
} else {
14038
14035
this->db = nullptr;
@@ -14060,8 +14057,7 @@ namespace sqlite_orm {
14060
14057
std::binary_semaphore _sync{1};
14061
14058
14062
14059
private:
14063
- alignas(
14064
- polyfill::hardware_destructive_interference_size) const std::function<void(sqlite3* db)> _onAfterOpen;
14060
+ alignas(polyfill::hardware_destructive_interference_size) const std::function<void(sqlite3* db)> _didOpenDb;
14065
14061
14066
14062
public:
14067
14063
const std::string filename;
@@ -14070,13 +14066,13 @@ namespace sqlite_orm {
14070
14066
struct connection_holder {
14071
14067
connection_holder(std::string filename,
14072
14068
bool /*openedForeverHint*/,
14073
- std::function<void(sqlite3*)> onAfterOpen ) :
14074
- _onAfterOpen {std::move(onAfterOpen )}, filename(std::move(filename)) {}
14069
+ std::function<void(sqlite3*)> didOpenDb ) :
14070
+ _didOpenDb {std::move(didOpenDb )}, filename(std::move(filename)) {}
14075
14071
14076
14072
connection_holder(const connection_holder&) = delete;
14077
14073
14078
- connection_holder(const connection_holder& other, std::function<void(sqlite3*)> onAfterOpen ) :
14079
- _onAfterOpen {std::move(onAfterOpen )}, filename{other.filename} {}
14074
+ connection_holder(const connection_holder& other, std::function<void(sqlite3*)> didOpenDb ) :
14075
+ _didOpenDb {std::move(didOpenDb )}, filename{other.filename} {}
14080
14076
14081
14077
void retain() {
14082
14078
// first one opens the connection.
@@ -14090,18 +14086,18 @@ namespace sqlite_orm {
14090
14086
if (rc != SQLITE_OK) SQLITE_ORM_CPP_UNLIKELY /*possible, but unexpected*/ {
14091
14087
throw_translated_sqlite_error(this->db);
14092
14088
}
14093
- }
14094
14089
14095
- if (_onAfterOpen) {
14096
- _onAfterOpen(this->db);
14090
+ if (_didOpenDb) {
14091
+ _didOpenDb(this->db);
14092
+ }
14097
14093
}
14098
14094
}
14099
14095
14100
14096
void release() {
14101
14097
// last one closes the connection.
14102
14098
// we assume that this might happen by any thread, therefore the counter must serve as a synchronization point.
14103
14099
if (_retainCount.fetch_sub(1, std::memory_order_acq_rel) == 1) {
14104
- int rc = sqlite3_close (this->db);
14100
+ int rc = sqlite3_close_v2 (this->db);
14105
14101
if (rc != SQLITE_OK) SQLITE_ORM_CPP_UNLIKELY {
14106
14102
throw_translated_sqlite_error(this->db);
14107
14103
} else {
@@ -14135,7 +14131,7 @@ namespace sqlite_orm {
14135
14131
#ifdef SQLITE_ORM_ALIGNED_NEW_SUPPORTED
14136
14132
alignas(polyfill::hardware_destructive_interference_size)
14137
14133
#endif
14138
- const std::function<void(sqlite3* db)> _onAfterOpen ;
14134
+ const std::function<void(sqlite3* db)> _didOpenDb ;
14139
14135
14140
14136
public:
14141
14137
const std::string filename;
@@ -24362,7 +24358,11 @@ namespace sqlite_orm {
24362
24358
SQLITE_ORM_EXPORT namespace sqlite_orm {
24363
24359
#ifdef SQLITE_ORM_CTAD_SUPPORTED
24364
24360
/*
24365
- * Factory function for a storage, from a database file and a bunch of database object definitions.
24361
+ * Factory function for a storage instance, from a database file, a set of database object definitions
24362
+ * and option storage options like connection control options and an 'on open' callback.
24363
+ *
24364
+ * E.g.
24365
+ * auto storage = make_storage("", connection_control{.open_forever = true}, on_open([](sqlite3* db) {}));
24366
24366
*/
24367
24367
template<class... Spec>
24368
24368
auto make_storage(std::string filename, Spec... specifications) {
0 commit comments