Initial commit
This commit is contained in:
commit
43e0a069d3
|
@ -0,0 +1,2 @@
|
||||||
|
use flake "git+https://gitea.c3d2.de/ehmry/meta?ref=flake#simplex_history_actor"
|
||||||
|
source_env ..
|
|
@ -0,0 +1 @@
|
||||||
|
/.direnv
|
|
@ -0,0 +1,2 @@
|
||||||
|
include ../syndicate-nim/depends.tup
|
||||||
|
NIM_FLAGS += --path:$(TUP_CWD)/../syndicate-nim/src
|
|
@ -0,0 +1,4 @@
|
||||||
|
version 1 .
|
||||||
|
|
||||||
|
Query = <sql @statement string @rows [Row ...]> .
|
||||||
|
Row = [string ...] .
|
|
@ -0,0 +1,8 @@
|
||||||
|
version = "20230526"
|
||||||
|
author = "Emery Hemingway"
|
||||||
|
description = "Syndicate Actor for accessing SQLite databases"
|
||||||
|
license = "Unlicense"
|
||||||
|
srcDir = "src"
|
||||||
|
bin = @["sqlite_actor"]
|
||||||
|
|
||||||
|
requires "nim >= 1.6.10", "syndicate >= 20230518"
|
|
@ -0,0 +1,4 @@
|
||||||
|
include_rules
|
||||||
|
: foreach ../*.prs |> !preserves_schema_nim |> {schema}
|
||||||
|
: sqlite_actor.nim | $(SYNDICATE_PROTOCOL) {schema} |> !nim_bin |> {bin}
|
||||||
|
: {bin} |> !assert_built |>
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
import
|
||||||
|
preserves
|
||||||
|
|
||||||
|
type
|
||||||
|
Query* {.preservesRecord: "sql".} = object
|
||||||
|
`statement`*: string
|
||||||
|
`rows`*: seq[Row]
|
||||||
|
|
||||||
|
Row* = seq[string]
|
||||||
|
proc `$`*(x: Query | Row): string =
|
||||||
|
`$`(toPreserve(x))
|
||||||
|
|
||||||
|
proc encode*(x: Query | Row): seq[byte] =
|
||||||
|
encode(toPreserve(x))
|
|
@ -0,0 +1,26 @@
|
||||||
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
# {.passC: staticExec("pkg-config --cflags sqlcipher").}
|
||||||
|
# {.passL: staticExec("pkg-config --libs sqlcipher").}
|
||||||
|
|
||||||
|
import std/db_sqlite
|
||||||
|
import preserves, syndicate
|
||||||
|
import ./sqlite
|
||||||
|
|
||||||
|
type Args {.preservesDictionary.}= object
|
||||||
|
database: string
|
||||||
|
dataspace: Ref
|
||||||
|
|
||||||
|
runActor("main") do (root: Ref; turn: var Turn):
|
||||||
|
connectStdio(root, turn)
|
||||||
|
let queryPat = ?Observe(pattern: !Query) ?? {0: grabLit()}
|
||||||
|
during(turn, root, ?Args) do (path: string, ds: Ref):
|
||||||
|
let db = open(path, "", "", "")
|
||||||
|
during(turn, ds, queryPat) do (statement: string):
|
||||||
|
var query = Query(statement: statement)
|
||||||
|
for row in rows(db, sql statement):
|
||||||
|
add(query.rows, row)
|
||||||
|
discard publish(turn, ds, query)
|
||||||
|
do:
|
||||||
|
close(db)
|
Loading…
Reference in New Issue