@@ -10,6 +10,7 @@ const HISTORY_FILE: &str = ".duckdb_rs_history";
10
10
struct SqlRepl {
11
11
conn : Connection ,
12
12
editor : Editor < ( ) , DefaultHistory > ,
13
+ debug : bool ,
13
14
}
14
15
15
16
impl SqlRepl {
@@ -22,10 +23,14 @@ impl SqlRepl {
22
23
let editor = {
23
24
let config = Config :: builder ( ) . auto_add_history ( true ) . build ( ) ;
24
25
let mut editor = Editor :: with_config ( config) . expect ( "Failed to create editor" ) ;
25
- let _ = editor. load_history ( HISTORY_FILE ) ; // Load history, might not exist yet
26
+ let _ = editor. load_history ( HISTORY_FILE ) ; // History might not exist yet
26
27
editor
27
28
} ;
28
- Ok ( SqlRepl { conn, editor } )
29
+ Ok ( SqlRepl {
30
+ conn,
31
+ editor,
32
+ debug : false ,
33
+ } )
29
34
}
30
35
31
36
fn run ( & mut self ) -> DuckResult < ( ) > {
@@ -52,6 +57,7 @@ impl SqlRepl {
52
57
eprintln ! ( "Error showing tables: {e}" ) ;
53
58
}
54
59
}
60
+ ".debug" => self . debug = !self . debug ,
55
61
_ => {
56
62
if let Err ( e) = self . execute_sql ( line) {
57
63
eprintln ! ( "{e}" ) ;
@@ -85,6 +91,7 @@ impl SqlRepl {
85
91
println ! ( " .quit - Exit the REPL" ) ;
86
92
println ! ( " .schema - Show database schema" ) ;
87
93
println ! ( " .tables - Show all tables" ) ;
94
+ println ! ( " .debug - Toggle debug output" ) ;
88
95
println ! ( ) ;
89
96
println ! ( "Keyboard shortcuts:" ) ;
90
97
println ! ( " Up/Down - Navigate command history" ) ;
@@ -108,7 +115,7 @@ impl SqlRepl {
108
115
if rbs. is_empty ( ) || rbs[ 0 ] . num_rows ( ) == 0 {
109
116
println ! ( "No tables found in database." ) ;
110
117
} else {
111
- print_records ( & rbs) ;
118
+ self . print_records ( & rbs) ;
112
119
}
113
120
114
121
Ok ( ( ) )
@@ -121,7 +128,7 @@ impl SqlRepl {
121
128
if rbs. is_empty ( ) || rbs[ 0 ] . num_rows ( ) == 0 {
122
129
println ! ( "No tables found in database." ) ;
123
130
} else {
124
- print_records ( & rbs) ;
131
+ self . print_records ( & rbs) ;
125
132
}
126
133
127
134
Ok ( ( ) )
@@ -145,7 +152,7 @@ impl SqlRepl {
145
152
if rbs. is_empty ( ) || rbs[ 0 ] . num_rows ( ) == 0 {
146
153
println ! ( "No results returned." ) ;
147
154
} else {
148
- print_records ( & rbs) ;
155
+ self . print_records ( & rbs) ;
149
156
}
150
157
} else {
151
158
// Execute non-query statements
@@ -154,14 +161,18 @@ impl SqlRepl {
154
161
155
162
Ok ( ( ) )
156
163
}
157
- }
158
164
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
+ fn print_records ( & self , rbs : & [ RecordBatch ] ) {
166
+ let options = arrow:: util:: display:: FormatOptions :: default ( )
167
+ . with_display_error ( true )
168
+ . with_types_info ( true ) ;
169
+ let table = arrow:: util:: pretty:: pretty_format_batches_with_options ( rbs, & options) . unwrap ( ) ;
170
+ println ! ( "{table}" ) ;
171
+
172
+ if self . debug {
173
+ dbg ! ( rbs) ;
174
+ }
175
+ }
165
176
}
166
177
167
178
fn main ( ) -> DuckResult < ( ) > {
0 commit comments