db-migrate-base
Advanced tools
Comparing version 2.3.0 to 2.3.1
151
index.js
@@ -11,3 +11,3 @@ var util = require('util'); | ||
var Base = Class.extend({ | ||
init: function (intern) { | ||
init: function(intern) { | ||
this._escapeDDL = this._escapeDDL || '"'; | ||
@@ -28,7 +28,7 @@ this._escapeString = this._escapeString || "'"; | ||
close: function () { | ||
close: function() { | ||
throw new Error('not implemented'); | ||
}, | ||
_translateSpecialDefaultValues: function ( | ||
_translateSpecialDefaultValues: function( | ||
spec, | ||
@@ -47,3 +47,3 @@ options, | ||
_prepareSpec: function (columnName, spec, options, tableName) { | ||
_prepareSpec: function(columnName, spec, options, tableName) { | ||
if (spec.defaultValue) { | ||
@@ -63,3 +63,3 @@ if (spec.defaultValue.raw) { | ||
mapDataType: function (str) { | ||
mapDataType: function(str) { | ||
switch (str) { | ||
@@ -101,3 +101,3 @@ case type.STRING: | ||
truncate: function (tableName, callback) { | ||
truncate: function(tableName, callback) { | ||
return this.runSql( | ||
@@ -108,3 +108,3 @@ 'TRUNCATE ' + this._escapeDDL + tableName + this._escapeDDL | ||
checkDBMS: function (dbms, callback) { | ||
checkDBMS: function(dbms, callback) { | ||
if (this.dbms === dbms) return Promise.resolve(dbms).nodeify(callback); | ||
@@ -114,19 +114,19 @@ else return Promise.reject('dbms does not match'); | ||
createDatabase: function () { | ||
createDatabase: function() { | ||
throw new Error('not implemented'); | ||
}, | ||
showDatabase: function () { | ||
showDatabase: function() { | ||
throw new Error('not implemented'); | ||
}, | ||
switchDatabase: function () { | ||
switchDatabase: function() { | ||
throw new Error('not implemented'); | ||
}, | ||
dropDatabase: function () { | ||
dropDatabase: function() { | ||
throw new Error('not implemented'); | ||
}, | ||
recurseCallbackArray: function (foreignKeys, callback) { | ||
recurseCallbackArray: function(foreignKeys, callback) { | ||
var fkFunc; | ||
@@ -142,3 +142,3 @@ var promises = []; | ||
bindForeignKey: function (tableName, columnName, fkOptions) { | ||
bindForeignKey: function(tableName, columnName, fkOptions) { | ||
var self = this; | ||
@@ -151,3 +151,3 @@ var mapping = {}; | ||
return function (callback) { | ||
return function(callback) { | ||
if (typeof callback === 'function') { | ||
@@ -174,3 +174,3 @@ self.addForeignKey( | ||
createColumnDef: function (name, spec, options) { | ||
createColumnDef: function(name, spec, options) { | ||
name = this._escapeDDL + name + this._escapeDDL; | ||
@@ -187,3 +187,3 @@ var type = this.mapDataType(spec.type); | ||
_createList: function (table, opt = {}) { | ||
_createList: function(table, opt = {}) { | ||
var options = { | ||
@@ -205,3 +205,3 @@ columns: { | ||
_createKV: function (table, opt = { valueJson: false }) { | ||
_createKV: function(table, opt = { valueJson: false }) { | ||
var options = { | ||
@@ -223,3 +223,3 @@ columns: { | ||
createMigrationsTable: function (callback) { | ||
createMigrationsTable: function(callback) { | ||
var options = { | ||
@@ -241,3 +241,3 @@ columns: { | ||
createSeedsTable: function (callback) { | ||
createSeedsTable: function(callback) { | ||
var options = { | ||
@@ -259,7 +259,7 @@ columns: { | ||
_handleMultiPrimaryKeys: function (primaryKeyColumns) { | ||
_handleMultiPrimaryKeys: function(primaryKeyColumns) { | ||
return util.format( | ||
', PRIMARY KEY (%s)', | ||
this.quoteDDLArr( | ||
primaryKeyColumns.map(function (value) { | ||
primaryKeyColumns.map(function(value) { | ||
return value.name; | ||
@@ -271,3 +271,3 @@ }) | ||
createTable: function (tableName, options, callback) { | ||
createTable: function(tableName, options, callback) { | ||
log.verbose('creating table:', tableName); | ||
@@ -353,3 +353,3 @@ var columnSpecs = options; | ||
.then( | ||
function () { | ||
function() { | ||
if (this._dbmControl === true) this._counter.signal(); | ||
@@ -363,3 +363,3 @@ | ||
dropTable: function (tableName, options, callback) { | ||
dropTable: function(tableName, options, callback) { | ||
if (arguments.length < 3 && typeof options === 'function') { | ||
@@ -385,7 +385,7 @@ callback = options; | ||
renameTable: function (tableName, newTableName, callback) { | ||
renameTable: function(tableName, newTableName, callback) { | ||
throw new Error('not implemented'); | ||
}, | ||
addColumn: function (tableName, columnName, columnSpec, callback) { | ||
addColumn: function(tableName, columnName, columnSpec, callback) { | ||
var columnSpec = this.normalizeColumnSpec(columnSpec); | ||
@@ -409,3 +409,3 @@ this._prepareSpec(columnName, columnSpec, {}, tableName); | ||
return this.runSql(sql) | ||
.then(function () { | ||
.then(function() { | ||
if (this._dbmControl === true) this._counter.signal(); | ||
@@ -420,15 +420,15 @@ | ||
removeColumn: function (tableName, columnName, callback) { | ||
removeColumn: function(tableName, columnName, callback) { | ||
throw new Error('not implemented'); | ||
}, | ||
renameColumn: function (tableName, oldColumnName, newColumnName, callback) { | ||
renameColumn: function(tableName, oldColumnName, newColumnName, callback) { | ||
throw new Error('not implemented'); | ||
}, | ||
changeColumn: function (tableName, columnName, columnSpec, callback) { | ||
changeColumn: function(tableName, columnName, columnSpec, callback) { | ||
throw new Error('not implemented'); | ||
}, | ||
quoteDDLArr: function (arr) { | ||
quoteDDLArr: function(arr) { | ||
for (var i = 0; i < arr.length; ++i) { | ||
@@ -441,3 +441,3 @@ arr[i] = this._escapeDDL + arr[i] + this._escapeDDL; | ||
quoteArr: function (arr) { | ||
quoteArr: function(arr) { | ||
for (var i = 0; i < arr.length; ++i) { | ||
@@ -450,3 +450,3 @@ arr[i] = this._escapeString + arr[i] + this._escapeString; | ||
addIndex: function (tableName, indexName, columns, unique, callback) { | ||
addIndex: function(tableName, indexName, columns, unique, callback) { | ||
if (typeof unique === 'function') { | ||
@@ -471,3 +471,3 @@ callback = unique; | ||
insert: function (tableName, valueArray, callback) { | ||
insert: function(tableName, valueArray, callback) { | ||
var columnNameArray = {}; | ||
@@ -543,3 +543,3 @@ | ||
update: function (tableName, valueArray, ids, callback) { | ||
update: function(tableName, valueArray, ids, callback) { | ||
var columnNameArray = {}; | ||
@@ -595,3 +595,3 @@ | ||
lookup: function (tableName, column, id, callback) { | ||
lookup: function(tableName, column, id, callback) { | ||
var sql = | ||
@@ -605,3 +605,3 @@ 'SELECT ' + | ||
return this.runSql(sql).then(function (row) { | ||
return this.runSql(sql).then(function(row) { | ||
return row[0]; | ||
@@ -611,3 +611,3 @@ }); | ||
removeIndex: function (tableName, indexName, callback) { | ||
removeIndex: function(tableName, indexName, callback) { | ||
if (arguments.length === 2 && typeof indexName === 'function') { | ||
@@ -624,11 +624,11 @@ callback = indexName; | ||
addForeignKey: function () { | ||
addForeignKey: function() { | ||
throw new Error('not implemented'); | ||
}, | ||
removeForeignKey: function () { | ||
removeForeignKey: function() { | ||
throw new Error('not implemented'); | ||
}, | ||
normalizeColumnSpec: function (obj) { | ||
normalizeColumnSpec: function(obj) { | ||
if (typeof obj === 'string') { | ||
@@ -641,3 +641,3 @@ return { type: obj }; | ||
_insertEntry: function (table, name) { | ||
_insertEntry: function(table, name) { | ||
return this.runSql( | ||
@@ -655,3 +655,3 @@ 'INSERT INTO ' + | ||
_insertKV: function (table, key, value) { | ||
_insertKV: function(table, key, value) { | ||
return this.runSql( | ||
@@ -666,7 +666,7 @@ `INSERT INTO ${this.escapeDDL(table)} | ||
_updateKV: function (table, key, value) { | ||
_updateKV: function(table, key, value) { | ||
return this.runSql( | ||
`UPDATE ${this.escapeDDL(table)} SET ${this.escapeDDL('value')} = ?, | ||
${this.escapeDDL('run_on')} = ? | ||
WHERE key = ?`, | ||
WHERE ${this.escapeDDL('key')} = ?`, | ||
[value, new Date(), key] | ||
@@ -676,3 +676,12 @@ ); | ||
addMigrationRecord: function (name, callback) { | ||
_updateKVC: function(table, key, value, c, v) { | ||
return this.runSql( | ||
`UPDATE ${this.escapeDDL(table)} SET ${this.escapeDDL('value')} = ?, | ||
${this.escapeDDL('run_on')} = ? | ||
WHERE ${this.escapeDDL('key')} = ? AND ${this.escapeDDL(c)} = ?`, | ||
[value, new Date(), key, v] | ||
); | ||
}, | ||
addMigrationRecord: function(name, callback) { | ||
this.runSql( | ||
@@ -691,3 +700,3 @@ 'INSERT INTO ' + | ||
addSeedRecord: function (name, callback) { | ||
addSeedRecord: function(name, callback) { | ||
this.runSql( | ||
@@ -706,6 +715,6 @@ 'INSERT INTO ' + | ||
startMigration: function (cb) { | ||
startMigration: function(cb) { | ||
return Promise.resolve().nodeify(cb); | ||
}, | ||
endMigration: function (cb) { | ||
endMigration: function(cb) { | ||
return Promise.resolve().nodeify(cb); | ||
@@ -715,7 +724,7 @@ }, | ||
// sql, callback | ||
runSql: function () { | ||
runSql: function() { | ||
throw new Error('not implemented'); | ||
}, | ||
_getList: function (table) { | ||
_getList: function(table) { | ||
var sql = | ||
@@ -731,3 +740,3 @@ 'SELECT * FROM ' + | ||
_getKV: function (table, key) { | ||
_getKV: function(table, key) { | ||
var sql = | ||
@@ -747,3 +756,3 @@ 'SELECT * FROM ' + | ||
*/ | ||
allLoadedMigrations: function (callback) { | ||
allLoadedMigrations: function(callback) { | ||
var sql = | ||
@@ -763,3 +772,3 @@ 'SELECT * FROM ' + | ||
*/ | ||
allLoadedSeeds: function (callback) { | ||
allLoadedSeeds: function(callback) { | ||
var sql = | ||
@@ -774,3 +783,3 @@ 'SELECT * FROM ' + | ||
_deleteEntry: function (table, entry) { | ||
_deleteEntry: function(table, entry) { | ||
var sql = | ||
@@ -785,3 +794,3 @@ 'DELETE FROM ' + | ||
_deleteKV: function (table, key) { | ||
_deleteExpired: function(table, expiry) { | ||
var sql = | ||
@@ -792,2 +801,12 @@ 'DELETE FROM ' + | ||
this._escapeDDL + | ||
' WHERE run_on <= ?'; | ||
return this.runSql(sql, [expiry]); | ||
}, | ||
_deleteKV: function(table, key) { | ||
var sql = | ||
'DELETE FROM ' + | ||
this._escapeDDL + | ||
table + | ||
this._escapeDDL + | ||
` WHERE ${this.escapeDDL('key')} = ?`; | ||
@@ -802,3 +821,3 @@ return this.runSql(sql, [key]); | ||
*/ | ||
deleteMigration: function (migrationName, callback) { | ||
deleteMigration: function(migrationName, callback) { | ||
var sql = | ||
@@ -834,3 +853,3 @@ 'DELETE FROM ' + | ||
*/ | ||
remove: function (table, ids, callback) { | ||
remove: function(table, ids, callback) { | ||
var sql = 'DELETE FROM ' + this._escapeDDL + table + +this._escapeDDL; | ||
@@ -862,3 +881,3 @@ // var searchClause = ''; | ||
*/ | ||
buildWhereClause: function (ids) { | ||
buildWhereClause: function(ids) { | ||
var searchClause = ''; | ||
@@ -898,4 +917,4 @@ | ||
(column.name = column.name || 'id'), | ||
(column.operator = column.operator || '='), | ||
(column.link = column.link || 'AND'); | ||
(column.operator = column.operator || '='), | ||
(column.link = column.link || 'AND'); | ||
@@ -968,3 +987,3 @@ if (!column.value) { | ||
*/ | ||
deleteSeed: function (seedName, callback) { | ||
deleteSeed: function(seedName, callback) { | ||
var sql = | ||
@@ -979,7 +998,7 @@ 'DELETE FROM ' + | ||
all: function (sql, params, callback) { | ||
all: function(sql, params, callback) { | ||
throw new Error('not implemented'); | ||
}, | ||
escape: function (str) { | ||
escape: function(str) { | ||
if (this._escapeString === "'") return str.replace(/'/g, "''"); | ||
@@ -989,7 +1008,7 @@ else return str.replace(/"/g, '"""'); | ||
escapeString: function (str) { | ||
escapeString: function(str) { | ||
return this._escapeString + this.escape(str) + this._escapeString; | ||
}, | ||
escapeDDL: function (str) { | ||
escapeDDL: function(str) { | ||
return this._escapeDDL + str + this._escapeDDL; | ||
@@ -996,0 +1015,0 @@ } |
{ | ||
"name": "db-migrate-base", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "db-migrate base driver", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
33387
901