Skip to content

Commit

Permalink
Merge pull request #185 from karthik2804/sqlite/update_return_types
Browse files Browse the repository at this point in the history
update sqlite return types to be more ergonomic
  • Loading branch information
karthik2804 authored Sep 11, 2023
2 parents 36b199b + 77d9c5c commit 31565a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions crates/spin-js-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,25 +745,25 @@ fn open_sqlite(context: &Context, _this: &Value, args: &[Value]) -> Result<Value

let mut serializer = Serializer::from_context(context)?;
let columns = result.columns;
columns.serialize(&mut serializer)?;
let js_columns = serializer.value;

let js_rows = context.array_value()?;
for row in result.rows {
let js_row = context.array_value()?;
for value in row.values {
let js_row = context.object_value()?;
for (index, value ) in row.values.iter().enumerate() {
let js_value = match value {
sqlite::ValueResult::Null => 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)?;
Expand Down
6 changes: 3 additions & 3 deletions spin-sdk/src/modules/spinSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ interface KvStore {
type SqliteParam = number | string | ArrayBuffer
type SqliteValue = null | number | string | ArrayBuffer


type SqliteRow = Record<string, SqliteValue>
interface SqliteReturn {
columns: string[],
rows: [
[SqliteValue]
]
rows: SqliteRow[]
}

interface SqliteStore {
Expand Down

0 comments on commit 31565a6

Please sign in to comment.