File tree Expand file tree Collapse file tree 1 file changed +4
-15
lines changed Expand file tree Collapse file tree 1 file changed +4
-15
lines changed Original file line number Diff line number Diff line change 11// Usage:
22// cargo run --example repl
33// cargo run --example repl path/to/database.db
4+ // cat example.sql | cargo run --example repl
45
56use duckdb:: { arrow:: record_batch:: RecordBatch , Connection , Result as DuckResult } ;
67use rustyline:: { error:: ReadlineError , history:: DefaultHistory , Config , Editor } ;
@@ -14,12 +15,8 @@ struct SqlRepl {
1415}
1516
1617impl SqlRepl {
17- fn new ( ) -> DuckResult < Self > {
18- Self :: new_with_file ( ":memory:" )
19- }
20-
21- fn new_with_file ( path : & str ) -> DuckResult < Self > {
22- let conn = Connection :: open ( path) ?;
18+ fn new ( path : Option < & str > ) -> DuckResult < Self > {
19+ let conn = Connection :: open ( path. unwrap_or ( ":memory:" ) ) ?;
2320 let editor = {
2421 let config = Config :: builder ( ) . auto_add_history ( true ) . build ( ) ;
2522 let mut editor = Editor :: with_config ( config) . expect ( "Failed to create editor" ) ;
@@ -176,14 +173,6 @@ impl SqlRepl {
176173}
177174
178175fn main ( ) -> DuckResult < ( ) > {
179- let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
180-
181- let mut repl = if args. len ( ) > 1 {
182- let db_path = & args[ 1 ] ;
183- SqlRepl :: new_with_file ( db_path) ?
184- } else {
185- SqlRepl :: new ( ) ?
186- } ;
187-
176+ let mut repl = SqlRepl :: new ( std:: env:: args ( ) . nth ( 1 ) . as_deref ( ) ) ?;
188177 repl. run ( )
189178}
You can’t perform that action at this time.
0 commit comments