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,131 @@
|
||||
import strformat, json, asyncdispatch
|
||||
|
||||
import ../src/allographer/query_builder
|
||||
import ../src/allographer/schema_builder
|
||||
|
||||
from connections import rdb
|
||||
|
||||
rdb.create([
|
||||
table("auth",[
|
||||
Column.increments("id"),
|
||||
Column.string("auth")
|
||||
]),
|
||||
table("users",[
|
||||
Column.increments("id"),
|
||||
Column.string("name").nullable(),
|
||||
Column.string("email").nullable(),
|
||||
Column.string("password").nullable(),
|
||||
Column.string("address").nullable(),
|
||||
Column.date("birth_date").nullable(),
|
||||
Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL)
|
||||
])
|
||||
])
|
||||
|
||||
# シーダー
|
||||
seeder rdb, "auth":
|
||||
rdb.table("auth").insert(@[
|
||||
%*{"auth": "admin"},
|
||||
%*{"auth": "user"}
|
||||
])
|
||||
.waitFor()
|
||||
|
||||
seeder rdb, "users":
|
||||
let total = 20
|
||||
var insertData: seq[JsonNode]
|
||||
for i in 1..total:
|
||||
let authId = if i mod 2 == 0: 1 else: 2
|
||||
insertData.add(
|
||||
%*{
|
||||
"name": &"user{i}",
|
||||
"email": &"user{i}@gmail.com",
|
||||
"password": &"password{i}",
|
||||
"auth_id": authId
|
||||
}
|
||||
)
|
||||
|
||||
rdb.table("users").insert(insertData).waitFor()
|
||||
|
||||
echo rdb.table("users").get().waitFor()
|
||||
|
||||
echo rdb
|
||||
.select("users.id", "users.email")
|
||||
.table("users")
|
||||
.where("name", "=", "user3")
|
||||
.orWhere("name", "=", "user4")
|
||||
.orWhere("users.id", "=", 5)
|
||||
.join("auth", "auth.id", "=", "users.auth_id")
|
||||
.limit(10)
|
||||
.get()
|
||||
.waitFor()
|
||||
|
||||
echo rdb.select("id", "email").table("users").limit(5).get().waitFor()
|
||||
echo rdb.select("id", "email").table("users").limit(5).first().waitFor()
|
||||
echo rdb.table("users").find(4).waitFor()
|
||||
echo rdb.select("id", "email").table("users").limit(5).find(3).waitFor()
|
||||
|
||||
echo ""
|
||||
|
||||
rdb.table("users").insert(%*{"name": "John", "email": "John@gmail.com"}).waitFor()
|
||||
echo rdb.table("users").insertId(%*{"name": "John", "email": "John@gmail.com"}).waitFor()
|
||||
|
||||
|
||||
rdb.table("users").insert(
|
||||
@[
|
||||
%*{"name": "John", "email": "John@gmail.com"},
|
||||
%*{"name": "Paul", "email": "Paul@gmail.com"}
|
||||
]
|
||||
)
|
||||
.waitFor()
|
||||
|
||||
rdb.table("users").insert(
|
||||
@[
|
||||
%*{"name": "Mick", "email": "Mick@gmail.com"},
|
||||
%*{"name": "Keith", "password": "KeithPass"}
|
||||
]
|
||||
)
|
||||
.waitFor()
|
||||
|
||||
|
||||
rdb.table("users").where("id", "=", 2).update(%*{"name": "David"}).waitFor()
|
||||
rdb.table("users").where("id", "=", 2).update(%*{"name": "David"}).waitFor()
|
||||
echo rdb.select().table("users").where("name", "=", "David").get().waitFor()
|
||||
echo rdb.table("users").find(2).waitFor()
|
||||
|
||||
rdb.table("users").where("name", "=", "David").delete().waitFor()
|
||||
rdb.table("users").delete(3).waitFor()
|
||||
echo rdb.table("users").find(3).waitFor()
|
||||
echo rdb.table("users").limit(5).get().waitFor()
|
||||
echo rdb.select("name").table("users").where("address", "is", nil).get().waitFor()
|
||||
|
||||
# sql check
|
||||
let r = rdb
|
||||
.select("users.id", "users.email")
|
||||
.table("users")
|
||||
.where("name", "=", "user3")
|
||||
.where("name", "=", "user4")
|
||||
.where("users.id", "=", 5)
|
||||
.orWhere("name", "=", "user6")
|
||||
.orWhere("users.id", "=", 7)
|
||||
.join("auth", "auth.id", "=", "users.auth_id")
|
||||
.limit(10)
|
||||
.get()
|
||||
.waitFor()
|
||||
echo r[0]["id"]
|
||||
echo r[0]["id"].type
|
||||
echo r[0]["email"]
|
||||
echo r[0]["email"].type
|
||||
|
||||
type User = ref object
|
||||
id:int
|
||||
name:string
|
||||
email:string
|
||||
password:string
|
||||
address:string
|
||||
birth_date:string
|
||||
auth_id:int
|
||||
let users = rdb.table("users").limit(5).get().orm(User).waitFor()
|
||||
for user in users:
|
||||
echo user.name
|
||||
|
||||
waitFor rdb.raw("DROP TABLE users").exec()
|
||||
waitFor rdb.raw("DROP TABLE auth").exec()
|
||||
Reference in New Issue
Block a user