syndesizer: assert SQL results to a seperate cap

This commit is contained in:
Emery Hemingway 2024-01-16 20:21:52 +02:00
parent 028df08d66
commit ff1f1ac44b
6 changed files with 17 additions and 13 deletions

View File

@ -146,9 +146,11 @@ let ?sqlspace = dataspace
}>
]
$sqlspace <query example-row "SELECT id, name FROM stuff">
let ?tuplespace = dataspace
$sqlspace ? <example-row ?id ?name> [
$sqlspace <query example-row "SELECT id, name FROM stuff" $tuplespace>
$tuplespace ? <example-row ?id ?name> [
$log ! <log "-" { row: <example-row $id $name> }>
]
```
@ -193,9 +195,11 @@ let ?sqlspace = dataspace
}>
]
$sqlspace <query example-row "SELECT id, name FROM stuff">
let ?tuplespace = dataspace
$sqlspace ? <example-row ?id ?name> [
$sqlspace <query example-row "SELECT id, name FROM stuff" $tuplespace>
$tuplespace ? <example-row ?id ?name> [
$log ! <log "-" { row: <example-row $id $name> }>
]
```

View File

@ -1,6 +1,5 @@
version 1 .
# When asserted the actor reponds with
# rows as records of the given label and
# row columns as record fields.
Query = <query @label any @statement string> .
# When asserted the actor reponds to @target rows as records
# of the given label and row columns as record fields.
Query = <query @label any @statement string @target #!any> .

View File

@ -6,6 +6,7 @@ type
Query* {.preservesRecord: "query".} = object
`label`*: Value
`statement`*: string
`target`* {.preservesEmbedded.}: Value
proc `$`*(x: Query): string =
`$`(toPreserves(x))

View File

@ -103,7 +103,7 @@ proc spawnPostgreActor*(turn: var Turn; root: Cap): Actor {.discardable.} =
statusHandle = publish(turn, ds,
initRecord("status", toSymbol($status), msg.toPreserves))
if status == CONNECTION_OK:
during(turn, ds, ?:Query) do (label: Value, statement: string):
during(turn, ds, ?:Query) do (label: Value, statement: string, target: Cap):
var res = PQexec(conn, statement)
var st = PQresultStatus(res)
discard publish(turn, ds, toRecord(
@ -116,7 +116,7 @@ proc spawnPostgreActor*(turn: var Turn; root: Cap): Actor {.discardable.} =
var rec = initRecord(label, fields)
for f in 0..<fields:
rec[f] = toPreserves($PQgetvalue(res, r, f))
discard publish(turn, ds, rec)
discard publish(turn, target, rec)
PQclear(res)
else:
stderr.writeLine "refusing to do anything when status is ", status

View File

@ -85,7 +85,7 @@ proc spawnSqliteActor*(turn: var Turn; root: Cap): Actor {.discardable.} =
if open_v2(path, addr db, SQLITE_OPEN_READONLY, nil) != SQLITE_OK:
logError(db, path)
else:
during(turn, ds, ?:Query) do (label: Value, statement: string):
during(turn, ds, ?:Query) do (label: Value, statement: string, target: Cap):
var stmt: Stmt
if prepare_v2(db, statement, statement.len.cint, addr stmt, nil) != SQLITE_OK:
logError(db, statement)
@ -95,7 +95,7 @@ proc spawnSqliteActor*(turn: var Turn; root: Cap): Actor {.discardable.} =
var res = step(stmt)
while res == SQLITE_ROW:
var rec = extractRecord(stmt, label, arity)
discard publish(turn, ds, rec)
discard publish(turn, target, rec)
res = step(stmt)
assert res != 100
if res != SQLITE_DONE:

View File

@ -1,6 +1,6 @@
# Package
version = "20240114"
version = "20240116"
author = "Emery Hemingway"
description = "Utilites for Syndicated Actors and Synit"
license = "unlicense"