Files
dimgigov 4e54075078
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
Add Ormin ORM support for BaraDB (Nim client)
2026-05-15 21:49:08 +03:00

50 lines
1.5 KiB
Nim

type
DbBackend* {.pure.} = enum
postgre, sqlite, mysql, baradb
import os
from ormin/importer_core import generateModelCode, ImportTarget
template importModel*(backend: DbBackend, filename: string, includeStatic: static[bool] = false) {.dirty.} =
## imports a model from an SQL file.
bind fileExists, parentDir, `/`
bind generateModelCode, ImportTarget
const file = static:
let path = parentDir(instantiationInfo(-1, true)[0])
path / filename & ".sql"
const importedFile = static:
if not includeStatic:
let res =
if fileExists("./tools/ormin_importer"):
gorgeEx("./tools/ormin_importer " & file)
else:
# run ormin_importer from the PATH
gorgeEx("ormin_importer " & file)
if res.exitCode != 0:
raise newException(Exception, "Failed to generate model: " & res.output)
file
{.warning: "Imported SQL Model: " & importedFile.}
const dbBackend = backend
import db_connector/db_common
when includeStatic:
import ormin/db_utils
when dbBackend == DbBackend.sqlite:
import ormin/ormin_sqlite
elif dbBackend == DbBackend.postgre:
import ormin/ormin_postgre
elif dbBackend == DbBackend.mysql:
import ormin/ormin_mysql
elif dbBackend == DbBackend.baradb:
import ormin/ormin_baradb
else:
{.error: "unknown database backend".}
when includeStatic:
generateModelCode(staticRead(file), file, ImportTarget(ord(backend)), true)
else:
include filename
include "ormin/queries"