File tree 3 files changed +28
-2
lines changed
3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,6 @@ pub(crate) async fn establish(options: &SqliteConnectOptions) -> Result<SqliteCo
29
29
} ) ?
30
30
. to_owned ( ) ;
31
31
32
- filename. push ( '\0' ) ;
33
-
34
32
// By default, we connect to an in-memory database.
35
33
// [SQLITE_OPEN_NOMUTEX] will instruct [sqlite3_open_v2] to return an error if it
36
34
// cannot satisfy our wish for a thread-safe, lock-free connection object
@@ -55,6 +53,13 @@ pub(crate) async fn establish(options: &SqliteConnectOptions) -> Result<SqliteCo
55
53
SQLITE_OPEN_PRIVATECACHE
56
54
} ;
57
55
56
+ if options. immutable {
57
+ filename = format ! ( "file:{}?immutable=true" , filename) ;
58
+ flags |= libsqlite3_sys:: SQLITE_OPEN_URI ;
59
+ }
60
+
61
+ filename. push ( '\0' ) ;
62
+
58
63
let busy_timeout = options. busy_timeout ;
59
64
60
65
let handle = blocking ! ( {
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ pub struct SqliteConnectOptions {
63
63
pub ( crate ) synchronous : SqliteSynchronous ,
64
64
pub ( crate ) auto_vacuum : SqliteAutoVacuum ,
65
65
pub ( crate ) page_size : u32 ,
66
+ pub ( crate ) immutable : bool ,
66
67
}
67
68
68
69
impl Default for SqliteConnectOptions {
@@ -88,6 +89,7 @@ impl SqliteConnectOptions {
88
89
synchronous : SqliteSynchronous :: Full ,
89
90
auto_vacuum : Default :: default ( ) ,
90
91
page_size : 4096 ,
92
+ immutable : false ,
91
93
}
92
94
}
93
95
@@ -190,4 +192,9 @@ impl SqliteConnectOptions {
190
192
self . page_size = page_size;
191
193
self
192
194
}
195
+
196
+ pub fn immutable ( mut self , immutable : bool ) -> Self {
197
+ self . immutable = immutable;
198
+ self
199
+ }
193
200
}
Original file line number Diff line number Diff line change @@ -94,6 +94,20 @@ impl FromStr for SqliteConnectOptions {
94
94
}
95
95
} ,
96
96
97
+ "immutable" => match & * value {
98
+ "true" | "1" => {
99
+ options. immutable = true ;
100
+ }
101
+ "false" | "0" => {
102
+ options. immutable = false ;
103
+ }
104
+ _ => {
105
+ return Err ( Error :: Configuration (
106
+ format ! ( "unknown value {:?} for `immutable`" , value) . into ( ) ,
107
+ ) ) ;
108
+ }
109
+ }
110
+
97
111
_ => {
98
112
return Err ( Error :: Configuration (
99
113
format ! (
You can’t perform that action at this time.
0 commit comments