Initial actoring

This commit is contained in:
Emery Hemingway 2023-06-10 13:15:23 +01:00
parent ecd5ee5eb0
commit 7d532d71dd
11 changed files with 81 additions and 12 deletions

2
.envrc Normal file
View File

@ -0,0 +1,2 @@
source_env ..
use nix

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# sqlite_actor
Syndicate actor for accessing Xapian databases.
Provides a Xapian binding module at [src/xapian_actor/xapian.nim](./src/xapian_actor/xapian.nim).

4
Tuprules.tup Normal file
View File

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

7
protocol.prs Normal file
View File

@ -0,0 +1,7 @@
version 1 .
DatabaseInfo = <xapian @uuid string @path string> .
Document = <document @id int @data bytes> .
ValueSlots = {int: any ...:...} .

5
shell.nix Normal file
View File

@ -0,0 +1,5 @@
let
syndicate = builtins.getFlake "syndicate";
pkgs =
import <nixpkgs> { overlays = builtins.attrValues syndicate.overlays; };
in pkgs.xapian_actor

3
src/Tupfile Normal file
View File

@ -0,0 +1,3 @@
include_rules
: xapian_actor.nim | ./xapian_actor/<protocol> $(SYNDICATE_PROTOCOL) |> !nim_bin |> {bin}
: {bin} |> !assert_built |>

25
src/xapian_actor.nim Normal file
View File

@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import preserves, syndicate
import ./xapian_actor/[protocol, xapian]
type
Value = Preserve[void]
type
DatabaseArg {.preservesDictionary.} = object
database: string
DataspaceArg {.preservesDictionary.} = object
dataspace: Ref
runActor("main") do (root: Ref; turn: var Turn):
connectStdio(root, turn)
during(turn, root, ?DatabaseArg) do (path: string):
let db = initDatabase(path)
during(turn, root, ?DataspaceArg) do (ds: Ref):
discard publish(turn, ds, DatabaseInfo(uuid: db.uuid, path: path))
do:
close(db)
# close database on path retraction

2
src/xapian_actor/Tupfile Normal file
View File

@ -0,0 +1,2 @@
include_rules
: foreach ../../*.prs |> !preserves_schema_nim |> | ./<protocol>

View File

@ -0,0 +1,19 @@
import
preserves, std/tables
type
Document* {.preservesRecord: "document".} = object
`id`*: BiggestInt
`data`*: seq[byte]
ValueSlots* = Table[BiggestInt, Preserve[void]]
DatabaseInfo* {.preservesRecord: "xapian".} = object
`uuid`*: string
`path`*: string
proc `$`*(x: Document | ValueSlots | DatabaseInfo): string =
`$`(toPreserve(x))
proc encode*(x: Document | ValueSlots | DatabaseInfo): seq[byte] =
encode(toPreserve(x))

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022 Emery Hemingway
# SPDX-FileCopyrightText: Emery Hemingway
#
# SPDX-License-Identifier: GPL-2.0-or-later

View File

@ -1,12 +1,9 @@
# Package
author = "Emery Hemingway"
backend = "cpp"
bin = @["xapian_actor"]
description = "Syndicate actor for accessing Xapian databases"
license = "Unlicense"
srcDir = "src"
version = "20220421"
version = "20220421"
author = "Emery Hemingway"
description = "Xapian library wrapper"
license = "GPL-2.0-or-later"
srcDir = "src"
# Dependencies
requires "nim >= 1.6.4"
requires "nim >= 1.6.4", "syndicate >= 20230609"