Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update sqlite return types to be more ergonomic #185

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading