Initial commit

This commit is contained in:
Emery Hemingway 2023-05-26 12:02:01 +01:00
commit 43e0a069d3
8 changed files with 62 additions and 0 deletions

2
.envrc Normal file
View File

@ -0,0 +1,2 @@
use flake "git+https://gitea.c3d2.de/ehmry/meta?ref=flake#simplex_history_actor"
source_env ..

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.direnv

2
Tuprules.tup Normal file
View File

@ -0,0 +1,2 @@
include ../syndicate-nim/depends.tup
NIM_FLAGS += --path:$(TUP_CWD)/../syndicate-nim/src

4
sqlite.prs Normal file
View File

@ -0,0 +1,4 @@
version 1 .
Query = <sql @statement string @rows [Row ...]> .
Row = [string ...] .

8
sqlite_actor.nimble Normal file
View File

@ -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"

4
src/Tupfile Normal file
View File

@ -0,0 +1,4 @@
include_rules
: foreach ../*.prs |> !preserves_schema_nim |> {schema}
: sqlite_actor.nim | $(SYNDICATE_PROTOCOL) {schema} |> !nim_bin |> {bin}
: {bin} |> !assert_built |>

15
src/sqlite.nim Normal file
View File

@ -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))

26
src/sqlite_actor.nim Normal file
View File

@ -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)