@@ -59,7 +59,7 @@ pub struct SqliteConnectOptions {
59
59
pub ( crate ) statement_cache_capacity : usize ,
60
60
pub ( crate ) busy_timeout : Duration ,
61
61
pub ( crate ) log_settings : LogSettings ,
62
- pub ( crate ) pragmas : IndexMap < String , String > ,
62
+ pub ( crate ) pragmas : IndexMap < Cow < ' static , str > , Cow < ' static , str > > ,
63
63
}
64
64
65
65
impl Default for SqliteConnectOptions {
@@ -71,14 +71,14 @@ impl Default for SqliteConnectOptions {
71
71
impl SqliteConnectOptions {
72
72
pub fn new ( ) -> Self {
73
73
// set default pragmas
74
- let mut pragmas = IndexMap :: new ( ) ;
74
+ let mut pragmas: IndexMap < Cow < ' static , str > , Cow < ' static , str > > = IndexMap :: new ( ) ;
75
75
76
76
let locking_mode: SqliteLockingMode = Default :: default ( ) ;
77
77
let auto_vacuum: SqliteAutoVacuum = Default :: default ( ) ;
78
78
79
79
// page_size must be set before any other action on the database.
80
- pragmas. insert ( "page_size" . into ( ) , 4096 . to_string ( ) ) ;
81
-
80
+ pragmas. insert ( "page_size" . into ( ) , " 4096" . into ( ) ) ;
81
+
82
82
// Note that locking_mode should be set before journal_mode; see
83
83
// https://www.sqlite.org/wal.html#use_of_wal_without_shared_memory .
84
84
pragmas. insert ( "locking_mode" . into ( ) , locking_mode. as_str ( ) . into ( ) ) ;
@@ -209,17 +209,21 @@ impl SqliteConnectOptions {
209
209
self
210
210
}
211
211
212
- /// Sets custom initial pragmas for the database connection.
213
- pub fn pragma ( mut self , key : & str , value : & str ) -> Self {
214
- self . pragmas . insert ( key. into ( ) , value. into ( ) ) ;
215
- self
216
- }
217
-
218
212
/// Sets the [page_size](https://www.sqlite.org/pragma.html#pragma_page_size) setting for the database connection.
219
213
///
220
214
/// The default page_size setting is 4096.
221
215
pub fn page_size ( mut self , page_size : u32 ) -> Self {
222
- self . pragmas . insert ( "page_size" . into ( ) , page_size. to_string ( ) ) ;
216
+ self . pragmas
217
+ . insert ( "page_size" . into ( ) , page_size. to_string ( ) . into ( ) ) ;
218
+ self
219
+ }
220
+
221
+ /// Sets custom initial pragma for the database connection.
222
+ pub fn pragma < T > ( mut self , key : T , value : T ) -> Self
223
+ where
224
+ T : Into < Cow < ' static , str > > ,
225
+ {
226
+ self . pragmas . insert ( key. into ( ) , value. into ( ) ) ;
223
227
self
224
228
}
225
229
}
0 commit comments