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

Commit db1a504c by Martin Aspeli

Improve pragma handling for sqlite3

1 parent 47f7e4c8
Showing with 7 additions and 12 deletions
...@@ -5,22 +5,17 @@ var Utils = require("../../utils") ...@@ -5,22 +5,17 @@ var Utils = require("../../utils")
module.exports = (function() { 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 = db = new sqlite3.Database(sequelize.options.storage || ':memory:', function(err) {
this.opened = false if(!err && sequelize.options.foreignKeys !== false) {
// Make it possible to define and use foreign key constraints unelss
// explicitly disallowed. It's still opt-in per relation
db.run('PRAGMA FOREIGN_KEYS=ON')
} }
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
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
}) })
} }
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
ConnectorManager.prototype.query = function(sql, callee, options) {
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!