File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments