@@ -81,21 +81,39 @@ namespace sqlite_orm {
81
81
polyfill::void_t <indirectly_test_preparable<decltype(std::declval<S>().prepare(std::declval<E>()))>>> =
82
82
true ;
83
83
84
+ template <class Opt , class OptionsTpl >
85
+ decltype (auto ) storage_opt_or_default(OptionsTpl& options) {
86
+ #ifdef SQLITE_ORM_CTAD_SUPPORTED
87
+ if constexpr (tuple_has_type<OptionsTpl, Opt>::value) {
88
+ return std::move (std::get<Opt>(options));
89
+ } else {
90
+ return Opt{};
91
+ }
92
+ #else
93
+ return Opt{};
94
+ #endif
95
+ }
96
+
84
97
/* *
85
98
* Storage class itself. Create an instanse to use it as an interfacto to sqlite db by calling `make_storage`
86
99
* function.
87
100
*/
88
101
template <class ... DBO>
89
102
struct storage_t : storage_base {
90
- using self = storage_t <DBO...> ;
103
+ using self_type = storage_t ;
91
104
using db_objects_type = db_objects_tuple<DBO...>;
92
105
93
106
/* *
94
107
* @param filename database filename.
95
108
* @param dbObjects db_objects_tuple
96
109
*/
97
- storage_t (std::string filename, db_objects_type dbObjects) :
98
- storage_base{std::move (filename), foreign_keys_count (dbObjects)}, db_objects{std::move (dbObjects)} {}
110
+ template <class OptionsTpl >
111
+ storage_t (std::string filename, db_objects_type dbObjects, OptionsTpl options) :
112
+ storage_base{std::move (filename),
113
+ storage_opt_or_default<connection_control>(options),
114
+ storage_opt_or_default<on_open_spec>(options),
115
+ foreign_keys_count (dbObjects)},
116
+ db_objects{std::move (dbObjects)} {}
99
117
100
118
storage_t (const storage_t &) = default ;
101
119
@@ -114,7 +132,7 @@ namespace sqlite_orm {
114
132
*
115
133
* Hence, friend was replaced by `obtain_db_objects()` and `pick_const_impl()`.
116
134
*/
117
- friend const db_objects_type& obtain_db_objects (const self & storage) noexcept {
135
+ friend const db_objects_type& obtain_db_objects (const self_type & storage) noexcept {
118
136
return storage.db_objects ;
119
137
}
120
138
@@ -246,7 +264,7 @@ namespace sqlite_orm {
246
264
247
265
public:
248
266
template <class T , class O = mapped_type_proxy_t <T>, class ... Args>
249
- mapped_view<O, self , Args...> iterate(Args&&... args) {
267
+ mapped_view<O, self_type , Args...> iterate(Args&&... args) {
250
268
this ->assert_mapped_type <O>();
251
269
252
270
auto con = this ->get_connection ();
@@ -781,7 +799,7 @@ namespace sqlite_orm {
781
799
std::enable_if_t <!is_prepared_statement<Ex>::value && !is_mapped<db_objects_type, Ex>::value,
782
800
bool > = true >
783
801
std::string dump (E&& expression, bool parametrized = false ) const {
784
- static_assert (is_preparable_v<self , Ex>, " Expression must be a high-level statement" );
802
+ static_assert (is_preparable_v<self_type , Ex>, " Expression must be a high-level statement" );
785
803
786
804
decltype (auto ) e2 = static_if<is_select<Ex>::value>(
787
805
[](auto expression) -> auto {
@@ -1702,17 +1720,50 @@ namespace sqlite_orm {
1702
1720
}
1703
1721
#endif // SQLITE_ORM_OPTIONAL_SUPPORTED
1704
1722
}; // struct storage_t
1723
+
1724
+ #ifdef SQLITE_ORM_CTAD_SUPPORTED
1725
+ template <class Elements >
1726
+ using dbo_index_sequence = filter_tuple_sequence_t <Elements, check_if_lacks<storage_opt_tag_t >::template fn>;
1727
+
1728
+ template <class Elements >
1729
+ using opt_index_sequence = filter_tuple_sequence_t <Elements, check_if_names<storage_opt_tag_t >::template fn>;
1730
+
1731
+ template <class ... DBO, class OptionsTpl >
1732
+ storage_t <DBO...> make_storage (std::string filename, std::tuple<DBO...> dbObjects, OptionsTpl options) {
1733
+ return {std::move (filename), std::move (dbObjects), std::move (options)};
1734
+ }
1735
+ #endif
1705
1736
}
1706
1737
}
1707
1738
1708
1739
SQLITE_ORM_EXPORT namespace sqlite_orm {
1740
+ #ifdef SQLITE_ORM_CTAD_SUPPORTED
1741
+ /*
1742
+ * Factory function for a storage instance, from a database file, a set of database object definitions
1743
+ * and option storage options like connection control options and an 'on open' callback.
1744
+ *
1745
+ * E.g.
1746
+ * auto storage = make_storage("", connection_control{.open_forever = true}, on_open([](sqlite3* db) {}));
1747
+ */
1748
+ template <class ... Spec>
1749
+ auto make_storage (std::string filename, Spec... specifications) {
1750
+ using namespace ::sqlite_orm::internal;
1751
+
1752
+ std::tuple specTuple{std::forward<Spec>(specifications)...};
1753
+ return internal::make_storage (
1754
+ std::move (filename),
1755
+ create_from_tuple<std::tuple>(std::move (specTuple), dbo_index_sequence<decltype (specTuple)>{}),
1756
+ create_from_tuple<std::tuple>(std::move (specTuple), opt_index_sequence<decltype (specTuple)>{}));
1757
+ }
1758
+ #else
1709
1759
/*
1710
- * Factory function for a storage, from a database file and a bunch of database object definitions.
1760
+ * Factory function for a storage instance , from a database file and a bunch of database object definitions.
1711
1761
*/
1712
1762
template <class ... DBO>
1713
1763
internal::storage_t <DBO...> make_storage (std::string filename, DBO... dbObjects) {
1714
- return {std::move (filename), internal::db_objects_tuple<DBO...> {std::forward<DBO>(dbObjects)...}};
1764
+ return {std::move (filename), {std::forward<DBO>(dbObjects)...}, std::tuple<>{ }};
1715
1765
}
1766
+ #endif
1716
1767
1717
1768
/* *
1718
1769
* sqlite3_threadsafe() interface.
0 commit comments