Skip to content

Commit

Permalink
close delete instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Kauto committed Aug 1, 2019
1 parent 06a1a75 commit ecb0f20
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/database.js
Expand Up @@ -195,6 +195,7 @@ DB.prototype.close = function () {
if (this.db) {
this.db.close()
this.db = undefined
if (this === instance) instance = null
}
return this
}
Expand Down Expand Up @@ -330,8 +331,8 @@ DB.prototype.update = function (table, data, where, whiteList) {
let parameter = []

// Build data part of the query
let setStringBuilder = []
for (let keyOfData in data) {
const setStringBuilder = []
for (const keyOfData in data) {
const value = data[keyOfData]
// don't set undefined and only values in an optional whitelist
if (value !== undefined && (!whiteList || whiteList.includes(keyOfData))) {
Expand All @@ -348,12 +349,12 @@ DB.prototype.update = function (table, data, where, whiteList) {
// Build where part of query
sql += ' WHERE '
if (Array.isArray(where)) {
let [whereTerm, ...whereParameter] = where
const [whereTerm, ...whereParameter] = where
sql += whereTerm
parameter = [...parameter, ...whereParameter]
} else if (typeof where === 'object') {
let whereStringBuilder = []
for (let keyOfWhere in where) {
const whereStringBuilder = []
for (const keyOfWhere in where) {
const value = where[keyOfWhere]
if (value !== undefined) {
parameter.push(value)
Expand Down Expand Up @@ -486,7 +487,7 @@ function createInsertOrReplaceStatement (insertOrReplace, table, data, whiteList

// Build start of where query
let sql = `${insertOrReplace} INTO \`${table}\` (\`${fields.join('`,`')}\`) VALUES `
let parameter = []
const parameter = []
let addComma = false

data.forEach(rowData => {
Expand Down Expand Up @@ -524,7 +525,7 @@ DB.prototype.migrate = function ({ force, table = 'migrations', migrationsPath =
// { id: 2, name: 'feature', fielname: '002-feature.sql', up: ..., down: ... }
migrations.map(migration => {
const filename = path.join(location, migration.filename)
let data = fs.readFileSync(filename, 'utf-8')
const data = fs.readFileSync(filename, 'utf-8')
const [up, down] = data.split(/^--\s+?down\b/mi)
if (!down) {
const message = `The ${migration.filename} file does not contain '-- Down' separator.`
Expand Down

0 comments on commit ecb0f20

Please sign in to comment.