File tree 1 file changed +21
-1
lines changed
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,13 @@ impl Config {
107
107
Ok ( self )
108
108
}
109
109
110
+ /// Add any setting to the config. DuckDB will return an error if the setting is unknown or
111
+ /// otherwise invalid.
112
+ pub fn with ( mut self , key : impl AsRef < str > , value : impl AsRef < str > ) -> Result < Config > {
113
+ self . set ( key. as_ref ( ) , value. as_ref ( ) ) ?;
114
+ Ok ( self )
115
+ }
116
+
110
117
fn set ( & mut self , key : & str , value : & str ) -> Result < ( ) > {
111
118
if self . config . is_none ( ) {
112
119
let mut config: ffi:: duckdb_config = ptr:: null_mut ( ) ;
@@ -184,7 +191,9 @@ mod test {
184
191
. enable_autoload_extension ( true ) ?
185
192
. allow_unsigned_extensions ( ) ?
186
193
. max_memory ( "2GB" ) ?
187
- . threads ( 4 ) ?;
194
+ . threads ( 4 ) ?
195
+ . with ( "preserve_insertion_order" , "true" ) ?;
196
+
188
197
let db = Connection :: open_in_memory_with_flags ( config) ?;
189
198
db. execute_batch ( "CREATE TABLE foo(x Text)" ) ?;
190
199
@@ -208,4 +217,15 @@ mod test {
208
217
209
218
Ok ( ( ) )
210
219
}
220
+
221
+ #[ test]
222
+ fn test_invalid_setting ( ) -> Result < ( ) > {
223
+ let config = Config :: default ( ) . with ( "some-invalid-setting" , "true" ) ?;
224
+ let res = Connection :: open_in_memory_with_flags ( config) ;
225
+ assert_eq ! (
226
+ res. unwrap_err( ) . to_string( ) ,
227
+ "Invalid Input Error: Unrecognized configuration property \" some-invalid-setting\" "
228
+ ) ;
229
+ Ok ( ( ) )
230
+ }
211
231
}
You can’t perform that action at this time.
0 commit comments