-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathormin.nim
More file actions
48 lines (41 loc) · 1.41 KB
/
ormin.nim
File metadata and controls
48 lines (41 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
type
DbBackend* {.pure.} = enum
postgre, sqlite, mysql
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
else:
{.error: "unknown database backend".}
when includeStatic:
generateModelCode(staticRead(file), file, ImportTarget(ord(backend)), true)
else:
include filename
include "ormin/queries"