From 77d9c5ce0b3e2b1acfb281f8165759873a01a110 Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Fri, 1 Sep 2023 09:14:59 -0700 Subject: [PATCH] update sqlite return types to be more ergonomic Signed-off-by: karthik2804 --- crates/spin-js-engine/src/lib.rs | 20 ++++++++++---------- spin-sdk/src/modules/spinSdk.ts | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/spin-js-engine/src/lib.rs b/crates/spin-js-engine/src/lib.rs index 1a882e1d..c9a791df 100644 --- a/crates/spin-js-engine/src/lib.rs +++ b/crates/spin-js-engine/src/lib.rs @@ -745,25 +745,25 @@ fn open_sqlite(context: &Context, _this: &Value, args: &[Value]) -> Result context.null_value()?, - sqlite::ValueResult::Integer(i) => context.value_from_i64(i)?, - sqlite::ValueResult::Real(r) => context.value_from_f64(r)?, - sqlite::ValueResult::Text(s) => context.value_from_str(&s)?, - sqlite::ValueResult::Blob(b) => context.array_buffer_value(&b)?, + sqlite::ValueResult::Integer(i) => context.value_from_i64(*i)?, + sqlite::ValueResult::Real(r) => context.value_from_f64(*r)?, + sqlite::ValueResult::Text(s) => context.value_from_str(s)?, + sqlite::ValueResult::Blob(b) => context.array_buffer_value(b)?, }; - js_row.append_property(js_value)?; + js_row.set_property(columns[index].to_string(),js_value)?; } js_rows.append_property(js_row)?; } + columns.serialize(&mut serializer)?; + let js_columns = serializer.value; + let result = context.object_value()?; result.set_property("columns", js_columns)?; result.set_property("rows", js_rows)?; diff --git a/spin-sdk/src/modules/spinSdk.ts b/spin-sdk/src/modules/spinSdk.ts index a585cf28..b61baef0 100644 --- a/spin-sdk/src/modules/spinSdk.ts +++ b/spin-sdk/src/modules/spinSdk.ts @@ -18,11 +18,11 @@ interface KvStore { type SqliteParam = number | string | ArrayBuffer type SqliteValue = null | number | string | ArrayBuffer + +type SqliteRow = Record interface SqliteReturn { columns: string[], - rows: [ - [SqliteValue] - ] + rows: SqliteRow[] } interface SqliteStore {