Skip to content

Commit

Permalink
update sqlite return types to be more ergonomic
Browse files Browse the repository at this point in the history
Signed-off-by: karthik2804 <karthik.ganeshram@fermyon.com>
  • Loading branch information
karthik2804 committed Sep 1, 2023
1 parent 5caf421 commit fc4d65f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions crates/spin-js-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,25 +746,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::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 fc4d65f

Please sign in to comment.