Add Ormin ORM support for BaraDB (Nim client)
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

This commit is contained in:
2026-05-15 21:49:08 +03:00
parent 2e945c1dcb
commit 4e54075078
63 changed files with 9764 additions and 0 deletions
@@ -0,0 +1,38 @@
## Ormin -- ORM for Nim.
## (c) 2017 Andreas Rumpf
## MIT License.
import strutils, os, parseopt
import ../ormin/importer_core
proc writeHelp() =
echo """
ormin <schema.sql> --out:<file.nim> --db:postgre|sqlite|mysql
"""
proc writeVersion() = echo "v1.0"
var p = initOptParser()
var infile = ""
var outfile = ""
var target: ImportTarget
for kind, key, val in p.getopt():
case kind
of cmdArgument:
infile = key
of cmdLongOption, cmdShortOption:
case key
of "help", "h": writeHelp()
of "version", "v": writeVersion()
of "out", "o": outfile = val
of "db": target = parseEnum[ImportTarget](val)
else: discard
of cmdEnd: assert(false) # cannot happen
if infile == "":
# no filename has been given, so we show the help:
writeHelp()
else:
if outfile == "":
outfile = changeFileExt(infile, "nim")
writeFile(outfile, generateModelCode(readFile(infile), absolutePath(infile), target))
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail
# Try default connection first, then fallback to -U postgres
run_psql_file() {
local db="$1"; shift
local file="$1"; shift
if ! psql -v ON_ERROR_STOP=1 -d "$db" -f "$file" "$@" >/dev/null 2>&1; then
psql -v ON_ERROR_STOP=1 -U postgres -d "$db" -f "$file" "$@"
fi
}
run_psql_cmd() {
local db="$1"; shift
local cmd="$1"; shift
if ! psql -v ON_ERROR_STOP=1 -d "$db" -c "$cmd" "$@" >/dev/null 2>&1; then
psql -v ON_ERROR_STOP=1 -U postgres -d "$db" -c "$cmd" "$@"
fi
}
# Create role 'test' if needed
run_psql_file postgres tools/setup_postgres_role.sql
# Create database 'test' if needed (must be outside DO block)
if ! psql -v ON_ERROR_STOP=1 -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname = 'test_ormin'" | grep -q 1; then
run_psql_cmd postgres "CREATE DATABASE test_ormin OWNER test"
fi
# Grant privileges on public schema
run_psql_cmd test_ormin "GRANT ALL PRIVILEGES ON SCHEMA public TO test"
echo "Postgres test DB/user ensured (role 'test', db 'test_ormin')."
@@ -0,0 +1,21 @@
DO
$$
BEGIN
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'test') THEN
CREATE ROLE test LOGIN PASSWORD 'test';
END IF;
END
$$;
DO
$$
BEGIN
IF NOT EXISTS (SELECT FROM pg_database WHERE datname = 'test') THEN
CREATE DATABASE test OWNER test;
END IF;
END
$$;
\connect test
GRANT ALL PRIVILEGES ON SCHEMA public TO test;
@@ -0,0 +1,9 @@
DO
$$
BEGIN
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'test') THEN
CREATE ROLE test LOGIN PASSWORD 'test';
END IF;
END
$$;