不要怂,就是干,撸起袖子干!

Commit 47f7e4c8 by Martin Aspeli

Turn on foreign key checking for SQLite

1 parent 6643167a
Showing with 11 additions and 0 deletions
...@@ -6,10 +6,21 @@ module.exports = (function() { ...@@ -6,10 +6,21 @@ module.exports = (function() {
var ConnectorManager = function(sequelize) { var ConnectorManager = function(sequelize) {
this.sequelize = sequelize this.sequelize = sequelize
this.database = new sqlite3.Database(sequelize.options.storage || ':memory:') this.database = new sqlite3.Database(sequelize.options.storage || ':memory:')
this.opened = false
} }
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype) Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
ConnectorManager.prototype.query = function(sql, callee, options) { ConnectorManager.prototype.query = function(sql, callee, options) {
var self = this
// Turn on foreign key checking (if the database has any) unless explicitly
// disallowed globally.
if(!this.opened && this.sequelize.options.foreignKeys !== false) {
this.database.serialize(function() {
self.database.run("PRAGMA FOREIGN_KEYS = ON")
self.opened = true
})
}
return new Query(this.database, this.sequelize, callee, options).run(sql) return new Query(this.database, this.sequelize, callee, options).run(sql)
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!