Skip to content

Commit dd81561

Browse files
committed
Simplify constructor
1 parent d39fc96 commit dd81561

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

crates/duckdb/examples/repl.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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

56
use duckdb::{arrow::record_batch::RecordBatch, Connection, Result as DuckResult};
67
use rustyline::{error::ReadlineError, history::DefaultHistory, Config, Editor};
@@ -14,12 +15,8 @@ struct SqlRepl {
1415
}
1516

1617
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:"))?;
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

178175
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())?;
188177
repl.run()
189178
}

0 commit comments

Comments
 (0)