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,97 @@
|
||||
discard """
|
||||
cmd: "nim c -d:reset -d:ssl $file"
|
||||
"""
|
||||
# nim c -r -d:reset -d:ssl tests/surrealdb/test_autoincrements.nim
|
||||
|
||||
import std/unittest
|
||||
import std/asyncdispatch
|
||||
import std/json
|
||||
import std/options
|
||||
import std/strformat
|
||||
import ../../src/allographer/query_builder
|
||||
import ../../src/allographer/schema_builder
|
||||
import ./connections
|
||||
import ../clear_tables
|
||||
|
||||
|
||||
let rdb = surreal
|
||||
|
||||
suite("autoincrements"):
|
||||
test("sequence table is not exists"):
|
||||
rdb.raw("REMOVE TABLE _autoincrement_sequences").exec().waitFor()
|
||||
|
||||
var info = rdb.raw("INFO FOR DB").info().waitFor()
|
||||
echo "info: ", info.pretty
|
||||
check not info[0]["result"]["tables"].contains("_autoincrement_sequences")
|
||||
|
||||
rdb.create(
|
||||
table("user", [
|
||||
Column.increments("index"),
|
||||
Column.string("name")
|
||||
])
|
||||
)
|
||||
|
||||
info = rdb.raw("INFO FOR DB").info().waitFor()
|
||||
echo "info: ", info.pretty
|
||||
check info[0]["result"]["tables"].contains("_autoincrement_sequences")
|
||||
|
||||
let id = rdb.table("user").insertId(%*{"name": "alice"}).waitFor()
|
||||
var user = rdb.table("user").find(id).waitFor().get()
|
||||
check user["name"].getStr == "alice"
|
||||
check user["index"].getInt == 1
|
||||
|
||||
rdb.update(id, %*{"name": "updated"}).waitFor()
|
||||
|
||||
user = rdb.table("user").find(id).waitFor().get()
|
||||
check user["name"].getStr == "updated"
|
||||
check user["index"].getInt == 1
|
||||
|
||||
|
||||
test("sequence table is exists"):
|
||||
var info = rdb.raw("INFO FOR DB").info().waitFor()
|
||||
check info[0]["result"]["tables"].contains("_autoincrement_sequences")
|
||||
|
||||
rdb.create(
|
||||
table("user", [
|
||||
Column.increments("index"),
|
||||
Column.string("name")
|
||||
])
|
||||
)
|
||||
|
||||
let id = rdb.table("user").insertId(%*{"name": "alice"}).waitFor()
|
||||
var user = rdb.table("user").find(id).waitFor().get()
|
||||
check user["name"].getStr == "alice"
|
||||
check user["index"].getInt == 1
|
||||
|
||||
rdb.update(id, %*{"name": "updated"}).waitFor()
|
||||
|
||||
user = rdb.table("user").find(id).waitFor().get()
|
||||
check user["name"].getStr == "updated"
|
||||
check user["index"].getInt == 1
|
||||
|
||||
|
||||
test("cycle"):
|
||||
rdb.create(
|
||||
table("user", [
|
||||
Column.increments("index"),
|
||||
Column.string("name")
|
||||
])
|
||||
)
|
||||
|
||||
var users: seq[JsonNode]
|
||||
for i in 1..100:
|
||||
users.add(%*{"name": &"user{i}"})
|
||||
rdb.table("user").insert(users).waitFor()
|
||||
|
||||
var user = rdb.table("user").where("index", "=", 1).first().waitFor().get()
|
||||
check user["index"].getInt == 1
|
||||
|
||||
user = rdb.table("user").where("index", "=", 50).first().waitFor().get()
|
||||
check user["index"].getInt == 50
|
||||
|
||||
user = rdb.table("user").where("index", "=", 100).first().waitFor().get()
|
||||
check user["index"].getInt == 100
|
||||
|
||||
echo rdb.table("user").orderBy("index", Asc).limit(20).get().waitFor()
|
||||
|
||||
clearTables(rdb).waitFor()
|
||||
Reference in New Issue
Block a user