aboutsummaryrefslogtreecommitdiff
path: root/src/guff/database.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/guff/database.cr')
-rw-r--r--src/guff/database.cr20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/guff/database.cr b/src/guff/database.cr
index 5b971b6..6882712 100644
--- a/src/guff/database.cr
+++ b/src/guff/database.cr
@@ -11,8 +11,28 @@ module Guff
WHERE type = 'table'
AND name = ?
",
+
+ pragma_foreign_keys: "
+ PRAGMA foreign_keys = true
+ ",
}
+ def initialize(path)
+ super(path)
+ query(SQL[:pragma_foreign_keys])
+ end
+
+ def initialize(path, &block)
+ super(path)
+ query(SQL[:pragma_foreign_keys])
+
+ begin
+ block.call(self)
+ ensure
+ close unless closed?
+ end
+ end
+
def table_exists?(table : String) : Bool
one(SQL[:table_exists], [table]) == table
end