Skip to content

Commit

Permalink
fix: query for duckdb
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Jun 22, 2024
1 parent 1211b06 commit 0cb8831
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1913,22 +1913,25 @@ mod duckdb {
let c = c.lock().expect("could not get lock on connection");

let mut stmt = c.prepare(&query)?;
let columns = stmt.column_names();

let columns_len = columns.len();
let rows = stmt
.query_map([], |r| {
let mut rows = Vec::with_capacity(columns_len);
for i in 0..columns_len {
let val = serde_json::Value::String(r.get_ref(i)?.as_str()?.to_owned());
let mut rows = Vec::new();
let mut index = 0;

while let Ok(val) = r.get_ref(index) {
let val = helpers::duckdb_value_to_json(val);
rows.push(val);
index += 1;
}

Ok(rows)
})?
.filter_map(|r| r.ok())
.collect::<Vec<_>>();

let columns = stmt.column_names();

eyre::Ok((columns, rows))
})
.await??;
Expand Down

0 comments on commit 0cb8831

Please sign in to comment.