From 7d532d71dd083cdf0c6ac47d090753bb66d6d41e Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sat, 10 Jun 2023 13:15:23 +0100 Subject: [PATCH] Initial actoring --- .envrc | 2 ++ README.md | 5 +++++ Tuprules.tup | 4 ++++ protocol.prs | 7 +++++++ shell.nix | 5 +++++ src/Tupfile | 3 +++ src/xapian_actor.nim | 25 +++++++++++++++++++++++++ src/xapian_actor/Tupfile | 2 ++ src/xapian_actor/protocol.nim | 19 +++++++++++++++++++ src/{ => xapian_actor}/xapian.nim | 2 +- xapian.nimble | 19 ++++++++----------- 11 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 .envrc create mode 100644 README.md create mode 100644 Tuprules.tup create mode 100644 protocol.prs create mode 100644 shell.nix create mode 100644 src/Tupfile create mode 100644 src/xapian_actor.nim create mode 100644 src/xapian_actor/Tupfile create mode 100644 src/xapian_actor/protocol.nim rename src/{ => xapian_actor}/xapian.nim (99%) diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..d324c24 --- /dev/null +++ b/.envrc @@ -0,0 +1,2 @@ +source_env .. +use nix diff --git a/README.md b/README.md new file mode 100644 index 0000000..466b61d --- /dev/null +++ b/README.md @@ -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). diff --git a/Tuprules.tup b/Tuprules.tup new file mode 100644 index 0000000..f28e9b7 --- /dev/null +++ b/Tuprules.tup @@ -0,0 +1,4 @@ +include ../syndicate-nim/depends.tup +NIM_FLAGS += --path:$(TUP_CWD)/../syndicate-nim/src + +NIM_FLAGS += --backend:cpp diff --git a/protocol.prs b/protocol.prs new file mode 100644 index 0000000..a8ca142 --- /dev/null +++ b/protocol.prs @@ -0,0 +1,7 @@ +version 1 . + +DatabaseInfo = . + +Document = . + +ValueSlots = {int: any ...:...} . diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..a122224 --- /dev/null +++ b/shell.nix @@ -0,0 +1,5 @@ +let + syndicate = builtins.getFlake "syndicate"; + pkgs = + import { overlays = builtins.attrValues syndicate.overlays; }; +in pkgs.xapian_actor diff --git a/src/Tupfile b/src/Tupfile new file mode 100644 index 0000000..81c40ec --- /dev/null +++ b/src/Tupfile @@ -0,0 +1,3 @@ +include_rules +: xapian_actor.nim | ./xapian_actor/ $(SYNDICATE_PROTOCOL) |> !nim_bin |> {bin} +: {bin} |> !assert_built |> diff --git a/src/xapian_actor.nim b/src/xapian_actor.nim new file mode 100644 index 0000000..56433c2 --- /dev/null +++ b/src/xapian_actor.nim @@ -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 diff --git a/src/xapian_actor/Tupfile b/src/xapian_actor/Tupfile new file mode 100644 index 0000000..c643d7a --- /dev/null +++ b/src/xapian_actor/Tupfile @@ -0,0 +1,2 @@ +include_rules +: foreach ../../*.prs |> !preserves_schema_nim |> | ./ diff --git a/src/xapian_actor/protocol.nim b/src/xapian_actor/protocol.nim new file mode 100644 index 0000000..b20a2b4 --- /dev/null +++ b/src/xapian_actor/protocol.nim @@ -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)) diff --git a/src/xapian.nim b/src/xapian_actor/xapian.nim similarity index 99% rename from src/xapian.nim rename to src/xapian_actor/xapian.nim index 31e0b63..73a9eae 100644 --- a/src/xapian.nim +++ b/src/xapian_actor/xapian.nim @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Emery Hemingway +# SPDX-FileCopyrightText: ☭ Emery Hemingway # # SPDX-License-Identifier: GPL-2.0-or-later diff --git a/xapian.nimble b/xapian.nimble index 285d2c7..d70d6ca 100644 --- a/xapian.nimble +++ b/xapian.nimble @@ -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"