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 1
1
// Usage:
2
2
// cargo run --example repl
3
3
// cargo run --example repl path/to/database.db
4
+ // cat example.sql | cargo run --example repl
4
5
5
6
use duckdb:: { arrow:: record_batch:: RecordBatch , Connection , Result as DuckResult } ;
6
7
use rustyline:: { error:: ReadlineError , history:: DefaultHistory , Config , Editor } ;
@@ -14,12 +15,8 @@ struct SqlRepl {
14
15
}
15
16
16
17
impl 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:" ) ) ?;
23
20
let editor = {
24
21
let config = Config :: builder ( ) . auto_add_history ( true ) . build ( ) ;
25
22
let mut editor = Editor :: with_config ( config) . expect ( "Failed to create editor" ) ;
@@ -176,14 +173,6 @@ impl SqlRepl {
176
173
}
177
174
178
175
fn 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 ( ) ) ?;
188
177
repl. run ( )
189
178
}
You can’t perform that action at this time.
0 commit comments