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

- 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:
2026-05-21 15:49:11 +03:00
parent 2d310a33a1
commit 6bfc5b3a3c
654 changed files with 109419 additions and 0 deletions
@@ -0,0 +1,12 @@
SQLITE_HOST="/root/project/example/db.sqlite3"
# SQLITE_HOST=":memory:"
PG_URL="postgresql://user:pass@postgres:5432/database"
MYSQL_URL="mysql://user:pass@mysql:3306/database"
MARIA_URL="mariadb://user:pass@mariadb:3306/database"
DB_MAX_CONNECTION=95
DB_TIMEOUT=30
# Logging
LOG_IS_DISPLAY=true
LOG_IS_FILE=false
LOG_DIR="/root/project/example/logs"
@@ -0,0 +1,17 @@
import std/asyncdispatch
import std/os
import std/strutils
import ../../src/allographer/connection
let
pgUrl = getEnv("PG_URL")
mariaUrl = getEnv("MARIA_URL")
mysqlUrl = getEnv("MYSQL_URL")
maxConnections = getEnv("DB_MAX_CONNECTION").parseInt
timeout = getEnv("DB_TIMEOUT").parseInt
# let rdb* = dbOpen(SQLite3, "./db.sqlite3", shouldDisplayLog=true)
let rdb* = dbOpen(PostgreSQL, pgUrl, maxConnections, timeout, shouldDisplayLog=true)
# let rdb* = dbOpen(Mariadb, mariaUrl, maxConnections, timeout, shouldDisplayLog=true)
# let rdb* = dbOpen(MySQL, mysqlUrl, maxConnections, timeout, shouldDisplayLog=true)
# let rdb* = dbOpen(SurrealDB, "test", "test", "user", "pass", "http://surreal", 8000, 5, 30, shouldDisplayLog=true).waitFor()
+5
View File
@@ -0,0 +1,5 @@
nim c -d:reset --threads:off ./migrations/migrate.nim
nim c --threads:off ./seeder/develop
./migrations/migrate
./seeder/develop
@@ -0,0 +1,42 @@
import std/json
import ../../../src/allographer/schema_builder
import ../connection
proc createAllTypeTable*() =
## 0002
rdb.create([
table("IntRelation", [
Column.increments("id")
]),
table("StrRelation", [
Column.uuid("uuid")
]),
table("Types", [
Column.increments("id"),
Column.integer("integer"),
Column.smallInteger("smallInteger"),
Column.mediumInteger("mediumInteger"),
Column.bigInteger("bigInteger"),
Column.decimal("decimal", 10, 3),
Column.double("double", 10, 3),
Column.float("float"),
Column.uuid("uuid"),
Column.char("char", 255),
Column.string("string"),
Column.text("text"),
Column.mediumText("mediumText"),
Column.longText("longText"),
Column.date("date"),
Column.datetime("datetime"),
Column.time("time"),
Column.timestamp("timestamp"),
Column.timestamps(),
Column.softDelete(),
Column.binary("binary"),
Column.boolean("boolean"),
Column.enumField("enumField", ["A", "B", "C"]),
Column.json("json"),
Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL),
Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL)
]),
])
@@ -0,0 +1,23 @@
import ../../../src/allographer/schema_builder
import ../connection
proc initDatabaase*() =
## 0001
rdb.create([
table("user", [
Column.uuid("id").index().comment("User ID"),
Column.string("name").comment("User name"),
Column.string("email").comment("User email address"),
Column.string("password").comment("User password"),
Column.integer("created_at").index().comment("Created at"),
Column.integer("updated_at").index().comment("Updated at"),
], "User table"),
table("post", [
Column.uuid("id").index().comment("Post ID"),
Column.string("title").comment("Post title"),
Column.string("content").comment("Post content"),
Column.strForeign("user_id").reference("id").onTable("user").comment("User ID"),
Column.integer("created_at").index().comment("Created at"),
Column.integer("updated_at").index().comment("Updated at"),
], "Post table"),
])
@@ -0,0 +1,12 @@
import std/asyncdispatch
import ../../../src/allographer/schema_builder
import ../connection
import ./init_databaase
import ./create_all_type_table
proc migrate*() =
initDatabaase()
createAllTypeTable()
migrate()
createSchema(rdb).waitFor()
+5
View File
@@ -0,0 +1,5 @@
nim c --threads:off ./migrations/migrate.nim
nim c --threads:off database/seeder/production
./migrations/migrate
APP_ENV=production ./database/seeder/production
@@ -0,0 +1,67 @@
import std/json
type IntRelationTable* = object
## IntRelation
id*: int
type StrRelationTable* = object
## StrRelation
uuid*: string
type UserTable* = object
## user
id*: string
name*: string
email*: string
password*: string
created_at*: int
updated_at*: int
type AuthTable* = object
## Auth
id*: int
auth*: string
type TypesTable* = object
## Types
id*: int
integer*: int
smallInteger*: int
mediumInteger*: int
bigInteger*: int
decimal*: float
double*: float
float*: float
uuid*: string
char*: string
string*: string
text*: string
mediumText*: string
longText*: string
date*: string
datetime*: string
time*: string
timestamp*: string
created_at*: string
updated_at*: string
deleted_at*: string
binary*: string
boolean*: bool
enumField*: string
json*: JsonNode
int_relation_id*: int
str_relation_id*: string
type PostTable* = object
## post
id*: string
title*: string
content*: string
user_id*: string
created_at*: int
updated_at*: int
@@ -0,0 +1,32 @@
import std/json
import std/strformat
import std/asyncdispatch
import std/oids
import std/times
import ../../../../src/allographer/query_builder
import ../../connection
import ../../schema
proc postSeeder*() {.async.} =
seeder(rdb, "post"):
let postCount = rdb.table("post").count().await
if postCount > 0:
return
let users = rdb.table("user").get().orm(UserTable).await
if users.len == 0:
raise newException(ValueError, "No users found in database")
var postList: seq[JsonNode]
for i in 1..users.len:
let row = PostTable(
id: $genOid(),
title: &"post {i}",
content: &"content {i}",
user_id: users[i-1].id,
created_at: now().toTime().toUnix().int,
updated_at: now().toTime().toUnix().int
)
postList.add(%row)
rdb.table("post").insert(postList).await
@@ -0,0 +1,24 @@
import std/json
import std/strformat
import std/asyncdispatch
import std/oids
import std/times
import ../../../../src/allographer/query_builder
import ../../connection
import ../../schema
proc userSeeder*() {.async.} =
seeder(rdb, "user"):
var userList: seq[JsonNode]
for i in 1..10:
let row = UserTable(
id: $genOid(),
name: &"user {i}",
email: &"user{i}@example.com",
password: &"password{i}",
created_at: now().toTime().toUnix().int,
updated_at: now().toTime().toUnix().int,
)
userList.add(%row)
rdb.table("user").insert(userList).await
@@ -0,0 +1,16 @@
import std/asyncdispatch
import std/os
import ./data/user_seeder
import ./data/post_seeder
proc seed() {.async.} =
let env = getEnv("APP_ENV")
if env != "develop":
raise newException(CatchableError, "This command is only available in the develop environment")
userSeeder().await
postSeeder().await
seed().waitFor()
@@ -0,0 +1,14 @@
import std/asyncdispatch
import std/os
import ./data/user_seeder
import ./data/post_seeder
proc seed() =
let env = getEnv("APP_ENV")
if env != "production":
raise newException(Exception, "This command is only available in the production environment")
userSeeder().waitFor()
postSeeder().waitFor()
seed()
@@ -0,0 +1,14 @@
import std/asyncdispatch
import std/os
import ./data/user_seeder
import ./data/post_seeder
proc seed() =
let env = getEnv("APP_ENV")
if env != "staging":
raise newException(Exception, "This command is only available in the staging environment")
userSeeder().waitFor()
postSeeder().waitFor()
seed()
+5
View File
@@ -0,0 +1,5 @@
nim c -d:reset --threads:off./migrations/migrate.nim
nim c --threads:off database/seeder/staging
./migrations/migrate
APP_ENV=staging ./database/seeder/staging