feat(clients): add nim-allographer client with BaraDB driver support
CI / test (push) Has been cancelled
CI / verify (push) Has been cancelled
Clients CI / build-server (push) Has been cancelled
Clients CI / test-python (push) Has been cancelled
Clients CI / test-javascript (push) Has been cancelled
Clients CI / test-nim (push) Has been cancelled
Clients CI / test-rust (push) Has been cancelled
CI / test (push) Has been cancelled
CI / verify (push) Has been cancelled
Clients CI / build-server (push) Has been cancelled
Clients CI / test-python (push) Has been cancelled
Clients CI / test-javascript (push) Has been cancelled
Clients CI / test-nim (push) Has been cancelled
Clients CI / test-rust (push) Has been cancelled
- Pure Nim wire protocol client (async + sync, no C FFI) - Query Builder: fluent API, SQL generator, execution, transactions - Schema Builder: create/alter/drop tables, column operations - Connection pool with aging and timeout handling - ORM integration via compile-time DB_BARADB switch - Tests: test_open, test_query - Documentation: README.md, PLAN_BARADB.md
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import std/asyncdispatch
|
||||
import std/json
|
||||
import ../../src/allographer/query_builder
|
||||
import ../../src/allographer/schema_builder
|
||||
import ../../src/allographer/connection
|
||||
|
||||
|
||||
let rdb = dbOpen(SurrealDB, "ns", "database", "user", "pass", "http://surreal", 8000, shouldDisplayLog=true).waitFor()
|
||||
|
||||
rdb.raw("""
|
||||
REMOVE TABLE `_sequences`;
|
||||
REMOVE EVENT `set_user_index` ON TABLE `user`;
|
||||
REMOVE TABLE `user`;
|
||||
REMOVE TABLE `auth`;
|
||||
""").exec().waitFor()
|
||||
|
||||
rdb.raw("""
|
||||
DEFINE TABLE `_sequences`;
|
||||
DEFINE FIELD `table_name` ON TABLE `_sequences` TYPE string;
|
||||
DEFINE FIELD `max_index` ON TABLE `_sequences` TYPE int;
|
||||
DEFINE INDEX `_sequences_table_name_unique` ON TABLE `_sequences` COLUMNS `table_name` UNIQUE;
|
||||
""").exec().waitFor()
|
||||
|
||||
rdb.raw("""
|
||||
DEFINE TABLE `user`;
|
||||
INSERT INTO `_sequences` {table_name: "user", max_index: 0};
|
||||
DEFINE FIELD `index` ON TABLE `user` TYPE int;
|
||||
DEFINE FIELD `name` ON TABLE `user` TYPE string;
|
||||
""").exec().waitFor()
|
||||
|
||||
rdb.raw("""
|
||||
DEFINE EVENT `set_user_index` ON TABLE `user` WHEN $event = "CREATE" THEN {
|
||||
LET $val = (SELECT `max_index` FROM `_sequences` WHERE `table_name` = "user" LIMIT 1)[0].max_index + 1;
|
||||
UPDATE `user` MERGE {index: $val} WHERE id = $after.id;
|
||||
UPDATE `_sequences` MERGE {max_index: $val} WHERE table_name = "user";
|
||||
};
|
||||
""").exec().waitFor()
|
||||
|
||||
echo rdb.raw("""
|
||||
INSERT INTO `user` {name: "user1"};
|
||||
SELECT * FROM `user`;
|
||||
SELECT * FROM `_sequences`;
|
||||
""").info().waitFor()
|
||||
|
||||
echo rdb.raw("""
|
||||
UPDATE `user` MERGE {name: "updated"} WHERE `name` = "user1";
|
||||
SELECT * FROM `user`;
|
||||
SELECT * FROM `_sequences`;
|
||||
""").info().waitFor()
|
||||
|
||||
|
||||
echo rdb.raw("""
|
||||
INSERT INTO `user` {name: "user2"};
|
||||
SELECT * FROM `user`;
|
||||
SELECT * FROM `_sequences`;
|
||||
""").info().waitFor()
|
||||
|
||||
echo rdb.raw("""
|
||||
UPDATE `user` MERGE {name: "updated2"} WHERE `name` = "user2";
|
||||
SELECT * FROM `user`;
|
||||
SELECT * FROM `_sequences`;
|
||||
""").info().waitFor()
|
||||
@@ -0,0 +1,49 @@
|
||||
import std/asyncdispatch
|
||||
import std/httpclient
|
||||
import std/streams
|
||||
import std/json
|
||||
import ../../src/allographer/connection
|
||||
import ../../src/allographer/query_builder
|
||||
import ../../src/allographer/schema_builder
|
||||
|
||||
proc main() {.async.} =
|
||||
let rdb = dbOpen(SurrealDB, "ns", "database", "user", "pass", "http://surreal", 8000, shouldDisplayLog=true).await
|
||||
|
||||
rdb.raw("""
|
||||
REMOVE TABLE `test`
|
||||
""").exec().await
|
||||
|
||||
rdb.raw("""
|
||||
DEFINE TABLE `test` SCHEMAFULL;
|
||||
DEFINE FIELD `bool` ON TABLE `test` TYPE bool;
|
||||
DEFINE FIELD `int` ON TABLE `test` TYPE int;
|
||||
DEFINE FIELD `float` ON TABLE `test` TYPE decimal;
|
||||
DEFINE FIELD `str` ON TABLE `test` TYPE string;
|
||||
DEFINE FIELD `data` ON TABLE `test` TYPE string | NONE;
|
||||
DEFINE FIELD `object` ON TABLE `test` TYPE object | NONE FLEXIBLE;
|
||||
""").exec().waitFor
|
||||
|
||||
echo rdb.table("test").columns().waitFor
|
||||
|
||||
rdb.raw("""
|
||||
INSERT INTO `test` {bool:?, int:?, float:?, str:?, object:?}
|
||||
""", %*[true, 1, 1.1, "alice", {"bool": false, "int": 2, "float": 2.1, "str": "two"}]).exec().waitFor
|
||||
|
||||
echo rdb.raw("""
|
||||
SELECT * FROM `test`
|
||||
""").get().waitFor
|
||||
|
||||
let client = newAsyncHttpClient()
|
||||
var veryLongText = ""
|
||||
var response = client.getContent("https://bible-api.com/genesis+1:1-31").await.parseJson
|
||||
veryLongText.add(response["text"].getStr)
|
||||
response = client.getContent("https://bible-api.com/genesis+2:1-25").await.parseJson
|
||||
veryLongText.add(response["text"].getStr)
|
||||
response = client.getContent("https://bible-api.com/genesis+3:1-24").await.parseJson
|
||||
veryLongText.add(response["text"].getStr)
|
||||
|
||||
rdb.table("test").insert(%*{"bool":false, "int":2, "float":2.1, "str": veryLongText}).waitFor
|
||||
|
||||
echo rdb.select("bool", "int", "float", "str").table("test").get().waitFor
|
||||
|
||||
main().waitFor
|
||||
Reference in New Issue
Block a user