6bfc5b3a3c
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
50 lines
1.7 KiB
Nim
50 lines
1.7 KiB
Nim
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
|