2
2
// cargo run --example repl
3
3
// cargo run --example repl path/to/database.db
4
4
5
- use duckdb:: {
6
- arrow:: { record_batch:: RecordBatch , util:: pretty:: print_batches} ,
7
- Connection , Result as DuckResult ,
8
- } ;
5
+ use duckdb:: { arrow:: record_batch:: RecordBatch , Connection , Result as DuckResult } ;
9
6
use rustyline:: { error:: ReadlineError , history:: DefaultHistory , Config , Editor } ;
10
7
11
8
const HISTORY_FILE : & str = ".duckdb_rs_history" ;
@@ -43,7 +40,7 @@ impl SqlRepl {
43
40
continue ;
44
41
}
45
42
match line {
46
- ".quit" | ".exit" => break ,
43
+ ".quit" => break ,
47
44
".help" => self . show_help ( ) ,
48
45
".schema" => {
49
46
if let Err ( e) = self . show_schema ( ) {
@@ -86,7 +83,6 @@ impl SqlRepl {
86
83
println ! ( "Available commands:" ) ;
87
84
println ! ( " .help - Show this help message" ) ;
88
85
println ! ( " .quit - Exit the REPL" ) ;
89
- println ! ( " .exit - Exit the REPL" ) ;
90
86
println ! ( " .schema - Show database schema" ) ;
91
87
println ! ( " .tables - Show all tables" ) ;
92
88
println ! ( ) ;
@@ -112,7 +108,7 @@ impl SqlRepl {
112
108
if rbs. is_empty ( ) || rbs[ 0 ] . num_rows ( ) == 0 {
113
109
println ! ( "No tables found in database." ) ;
114
110
} else {
115
- print_batches ( & rbs) . unwrap ( ) ;
111
+ print_records ( & rbs) ;
116
112
}
117
113
118
114
Ok ( ( ) )
@@ -125,7 +121,7 @@ impl SqlRepl {
125
121
if rbs. is_empty ( ) || rbs[ 0 ] . num_rows ( ) == 0 {
126
122
println ! ( "No tables found in database." ) ;
127
123
} else {
128
- print_batches ( & rbs) . unwrap ( ) ;
124
+ print_records ( & rbs) ;
129
125
}
130
126
131
127
Ok ( ( ) )
@@ -149,7 +145,7 @@ impl SqlRepl {
149
145
if rbs. is_empty ( ) || rbs[ 0 ] . num_rows ( ) == 0 {
150
146
println ! ( "No results returned." ) ;
151
147
} else {
152
- print_batches ( & rbs) . unwrap ( ) ;
148
+ print_records ( & rbs) ;
153
149
}
154
150
} else {
155
151
// Execute non-query statements
@@ -160,6 +156,14 @@ impl SqlRepl {
160
156
}
161
157
}
162
158
159
+ fn print_records ( rbs : & [ RecordBatch ] ) {
160
+ let options = arrow:: util:: display:: FormatOptions :: default ( )
161
+ . with_display_error ( true )
162
+ . with_types_info ( true ) ;
163
+ let str = arrow:: util:: pretty:: pretty_format_batches_with_options ( rbs, & options) . unwrap ( ) ;
164
+ println ! ( "{str}" ) ;
165
+ }
166
+
163
167
fn main ( ) -> DuckResult < ( ) > {
164
168
let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
165
169
0 commit comments