Skip to content

Commit 2319bbb

Browse files
committed
update
Signed-off-by: George Lemon <georgelemon@protonmail.com>
1 parent 04b0e96 commit 2319bbb

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/ozark/query.nim

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@ macro prepareTable*(modelName): untyped =
107107
)
108108
)
109109

110-
macro dropTable*(modelName): untyped =
110+
macro dropTable*(modelName: untyped, cascade: static bool = false): untyped =
111111
## Compile-time macro to drop a model's table from the database.
112112
withTableCheck(modelName):
113113
let tableName = getTableName($modelName[1])
114114
result = newCall(
115115
bindSym"ozarkRawSQLResult",
116-
newLit("DROP TABLE IF EXISTS " & tableName),
116+
newLit("DROP TABLE IF EXISTS " & tableName & (
117+
if cascade: " CASCADE" else: ""
118+
)),
117119
)
118120

119121
#
@@ -517,6 +519,15 @@ macro exec*(sql: untyped) =
517519
randId.repr,
518520
"0"
519521
])
522+
of nkDropTable, nkDropTableIfExists, nkDropIfExists:
523+
let randId = genSym(nskVar, "id")
524+
let stub = staticRead("private" / "stubs" / "execSql.nim")
525+
result = macros.parseStmt(stub % [
526+
$sql[1],
527+
"",
528+
randId.repr,
529+
"0"
530+
])
520531
of nkDelete:
521532
discard # todo
522533
else: discard

0 commit comments

Comments
 (0)