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
49 lines
1.3 KiB
Nim
49 lines
1.3 KiB
Nim
import std/asyncdispatch
|
|
import std/json
|
|
import std/httpclient
|
|
import std/streams
|
|
import std/options
|
|
import ../src/allographer/connection
|
|
import ../src/allographer/query_builder
|
|
|
|
|
|
proc main() {.async.} =
|
|
let client = newAsyncHttpClient()
|
|
let response = client.getContent("https://nim-lang.org/assets/img/twitter_banner.png").await
|
|
let imageStream = newStringStream(response)
|
|
let binaryImage = imageStream.readAll()
|
|
|
|
|
|
let rdb = dbOpen(SQLite3, "/root/project/db.sqlite3", shouldDisplayLog=true)
|
|
echo rdb.type
|
|
|
|
rdb.raw("DROP TABLE IF EXISTS \"test\"").exec().await
|
|
|
|
rdb.raw("""
|
|
CREATE TABLE IF NOT EXISTS "test" (
|
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
'blob' BLOB,
|
|
'int' INTEGER,
|
|
'float' NUMERIC,
|
|
'str' VARCHAR
|
|
)"""
|
|
).exec().await
|
|
|
|
rdb.table("test").insert(%*{"blob":binaryImage, "int": 1, "float": 1.1, "str": "alice"}).await
|
|
|
|
let res = rdb.select("id", "int", "float", "str").table("test").get().await
|
|
for row in res:
|
|
echo row
|
|
|
|
var row = rdb.select("id", "int", "float", "str").table("test").first().await
|
|
if row.isSome:
|
|
echo row.get
|
|
|
|
rdb.table("test").where("id", "=", 1).update(%*{"str": "bob"}).await
|
|
|
|
row = rdb.select("id", "int", "float", "str").table("test").find(1).await
|
|
if row.isSome:
|
|
echo row.get
|
|
|
|
main().waitFor
|