@@ -37,7 +37,7 @@ impl DuckDBObject {
3737pub struct DuckClient {
3838 pub db : Database ,
3939 pub connection : Connection ,
40- pub db_path : Option < PathBuf > ,
40+ pub db_path : PathBuf ,
4141 pub threads : Option < usize > ,
4242}
4343
@@ -49,22 +49,21 @@ impl DuckClient {
4949 delete_database : bool ,
5050 threads : Option < usize > ,
5151 ) -> Result < Self > {
52- let db_path = if data_url. scheme ( ) != "file" {
53- None
54- } else {
55- let base_path = data_url
52+ let base_path = if data_url. scheme ( ) == "file" {
53+ data_url
5654 . to_file_path ( )
57- . map_err ( |_| anyhow:: anyhow!( "Invalid file URL: {}" , data_url) ) ?;
58- let dir = base_path. join ( format. name ( ) ) ;
59- std:: fs:: create_dir_all ( & dir) ?;
60- let db_path = dir. join ( "duckdb.db" ) ;
61- if delete_database && db_path. exists ( ) {
62- std:: fs:: remove_file ( & db_path) ?;
63- }
64- Some ( db_path)
55+ . map_err ( |_| anyhow:: anyhow!( "Invalid file URL: {}" , data_url) ) ?
56+ } else {
57+ std:: env:: temp_dir ( ) . join ( "vortex-ddb-bench" )
6558 } ;
59+ let dir = base_path. join ( format. name ( ) ) ;
60+ std:: fs:: create_dir_all ( & dir) ?;
61+ let db_path = dir. join ( "duckdb.db" ) ;
62+ if delete_database && db_path. exists ( ) {
63+ std:: fs:: remove_file ( & db_path) ?;
64+ }
6665
67- let ( db, connection) = Self :: open_and_setup_database ( db_path. clone ( ) , threads) ?;
66+ let ( db, connection) = Self :: open_and_setup_database ( Some ( db_path. clone ( ) ) , threads) ?;
6867
6968 Ok ( Self {
7069 db,
@@ -123,7 +122,7 @@ impl DuckClient {
123122 drop ( db) ;
124123
125124 let ( mut db, mut connection) =
126- Self :: open_and_setup_database ( self . db_path . clone ( ) , self . threads ) ?;
125+ Self :: open_and_setup_database ( Some ( self . db_path . clone ( ) ) , self . threads ) ?;
127126
128127 std:: mem:: swap ( & mut self . connection , & mut connection) ;
129128 std:: mem:: swap ( & mut self . db , & mut db) ;
@@ -132,11 +131,14 @@ impl DuckClient {
132131 }
133132
134133 pub fn new_in_memory ( ) -> Result < Self > {
135- let ( db, connection) = Self :: open_and_setup_database ( None , None ) ?;
134+ let dir = std:: env:: temp_dir ( ) . join ( "vortex-ddb-bench" ) . join ( "in-memory" ) ;
135+ std:: fs:: create_dir_all ( & dir) ?;
136+ let db_path = dir. join ( "duckdb.db" ) ;
137+ let ( db, connection) = Self :: open_and_setup_database ( Some ( db_path. clone ( ) ) , None ) ?;
136138 Ok ( Self {
137139 db,
138140 connection,
139- db_path : None ,
141+ db_path,
140142 threads : None ,
141143 } )
142144 }
0 commit comments