From 0cb88317ac14db71f47cacc25ea0805f1d019300 Mon Sep 17 00:00:00 2001 From: frectonz Date: Sat, 22 Jun 2024 07:40:09 +0300 Subject: [PATCH] fix: query for duckdb --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index d2e7ec7..4685fd3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1913,15 +1913,16 @@ 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) @@ -1929,6 +1930,8 @@ mod duckdb { .filter_map(|r| r.ok()) .collect::>(); + let columns = stmt.column_names(); + eyre::Ok((columns, rows)) }) .await??;