Skip to content
Merged
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
26 changes: 16 additions & 10 deletions platform/Sqlite.roc
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,19 @@ Sqlite :: [].{
## Execute a SQL query and decode exactly one row into a value. `bindings`
## is a `List(Binding)` and `row` is a decoder built from the functions below.
query! = |{ path, query: q, bindings, row }| {
stmt = prepare!({ path, query: q })?
stmt.query!(bindings, row)
match prepare!({ path, query: q }) {
Err(e) => Err(e)
Ok(stmt) => stmt.query!(bindings, row)
}
}

## Execute a SQL query and decode multiple rows into a list of values.
## `bindings` is a `List(Binding)` and `rows` is a row decoder.
query_many! = |{ path, query: q, bindings, rows }| {
stmt = prepare!({ path, query: q })?
stmt.query_many!(bindings, rows)
match prepare!({ path, query: q }) {
Err(e) => Err(e)
Ok(stmt) => stmt.query_many!(bindings, rows)
}
}

# ---- Row decoding combinators ----------------------------------------------
Expand Down Expand Up @@ -393,13 +397,15 @@ decode_rows! = |stmt, gen_decode| {
cols = sqlite_columns!(stmt)
decode_row! = gen_decode(cols)
helper! = |out|
match sqlite_step!(stmt)? {
Done => Ok(out)
Row => {
row = decode_row!(stmt)?
helper!(out.append(row))
match sqlite_step!(stmt) {
Err(e) => Err(e)
Ok(Done) => Ok(out)
Ok(Row) =>
match decode_row!(stmt) {
Err(e) => Err(e)
Ok(row) => helper!(out.append(row))
}
}
}
helper!([])
}

Expand Down
Loading