mirror of
https://github.com/knex/knex.git
synced 2025-12-28 07:29:16 +00:00
Name Bluebird usage explicitly. Remove spread and thenReturn (#3285)
This commit is contained in:
parent
04b12f234b
commit
1e950b93e4
16
bin/cli.js
16
bin/cli.js
@ -1,14 +1,14 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint no-console:0, no-var:0 */
|
||||
const Liftoff = require('liftoff');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const interpret = require('interpret');
|
||||
const path = require('path');
|
||||
const tildify = require('tildify');
|
||||
const commander = require('commander');
|
||||
const color = require('colorette');
|
||||
const argv = require('getopts')(process.argv.slice(2));
|
||||
const fs = Promise.promisifyAll(require('fs'));
|
||||
const fs = Bluebird.promisifyAll(require('fs'));
|
||||
const cliPkg = require('../package');
|
||||
const {
|
||||
mkConfigObj,
|
||||
@ -220,7 +220,7 @@ function invoke(env) {
|
||||
.action(() => {
|
||||
pending = initKnex(env, commander.opts())
|
||||
.migrate.latest()
|
||||
.spread((batchNo, log) => {
|
||||
.then(([batchNo, log]) => {
|
||||
if (log.length === 0) {
|
||||
success(color.cyan('Already up to date'));
|
||||
}
|
||||
@ -238,7 +238,7 @@ function invoke(env) {
|
||||
.action(() => {
|
||||
pending = initKnex(env, commander.opts())
|
||||
.migrate.up()
|
||||
.spread((batchNo, log) => {
|
||||
.then(([batchNo, log]) => {
|
||||
if (log.length === 0) {
|
||||
success(color.cyan('Already up to date'));
|
||||
}
|
||||
@ -264,7 +264,7 @@ function invoke(env) {
|
||||
|
||||
pending = initKnex(env, commander.opts())
|
||||
.migrate.rollback(null, all)
|
||||
.spread((batchNo, log) => {
|
||||
.then(([batchNo, log]) => {
|
||||
if (log.length === 0) {
|
||||
success(color.cyan('Already at the base migration'));
|
||||
}
|
||||
@ -283,7 +283,7 @@ function invoke(env) {
|
||||
.action(() => {
|
||||
pending = initKnex(env, commander.opts())
|
||||
.migrate.down()
|
||||
.spread((batchNo, log) => {
|
||||
.then(([batchNo, log]) => {
|
||||
if (log.length === 0) {
|
||||
success(color.cyan('Already at the base migration'));
|
||||
}
|
||||
@ -342,7 +342,7 @@ function invoke(env) {
|
||||
.action(() => {
|
||||
pending = initKnex(env, commander.opts())
|
||||
.seed.run()
|
||||
.spread((log) => {
|
||||
.then(([log]) => {
|
||||
if (log.length === 0) {
|
||||
success(color.cyan('No seed files exist'));
|
||||
}
|
||||
@ -356,7 +356,7 @@ function invoke(env) {
|
||||
|
||||
commander.parse(process.argv);
|
||||
|
||||
Promise.resolve(pending).then(() => {
|
||||
Bluebird.resolve(pending).then(() => {
|
||||
commander.outputHelp();
|
||||
exit('Unknown command-line options, exiting');
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
const Raw = require('./raw');
|
||||
const Ref = require('./ref');
|
||||
@ -255,7 +255,7 @@ assign(Client.prototype, {
|
||||
connection.__knexUid = uniqueId('__knexUid');
|
||||
|
||||
if (poolConfig.afterCreate) {
|
||||
return Promise.promisify(poolConfig.afterCreate)(connection);
|
||||
return Bluebird.promisify(poolConfig.afterCreate)(connection);
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -302,21 +302,21 @@ assign(Client.prototype, {
|
||||
// Acquire a connection from the pool.
|
||||
acquireConnection() {
|
||||
if (!this.pool) {
|
||||
return Promise.reject(new Error('Unable to acquire a connection'));
|
||||
return Bluebird.reject(new Error('Unable to acquire a connection'));
|
||||
}
|
||||
try {
|
||||
return Promise.try(() => this.pool.acquire().promise)
|
||||
return Bluebird.try(() => this.pool.acquire().promise)
|
||||
.tap((connection) => {
|
||||
debug('acquired connection from pool: %s', connection.__knexUid);
|
||||
})
|
||||
.catch(TimeoutError, () => {
|
||||
throw new Promise.TimeoutError(
|
||||
throw new Bluebird.TimeoutError(
|
||||
'Knex: Timeout acquiring a connection. The pool is probably full. ' +
|
||||
'Are you missing a .transacting(trx) call?'
|
||||
);
|
||||
});
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
return Bluebird.reject(e);
|
||||
}
|
||||
},
|
||||
|
||||
@ -330,14 +330,14 @@ assign(Client.prototype, {
|
||||
debug('pool refused connection: %s', connection.__knexUid);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
return Bluebird.resolve();
|
||||
},
|
||||
|
||||
// Destroy the current connection pool for the client.
|
||||
destroy(callback) {
|
||||
const maybeDestroy = this.pool && this.pool.destroy();
|
||||
|
||||
return Promise.resolve(maybeDestroy)
|
||||
return Bluebird.resolve(maybeDestroy)
|
||||
.then(() => {
|
||||
this.pool = void 0;
|
||||
|
||||
@ -350,7 +350,7 @@ assign(Client.prototype, {
|
||||
callback(err);
|
||||
}
|
||||
|
||||
return Promise.reject(err);
|
||||
return Bluebird.reject(err);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ const { assign, map, flatten, values } = require('lodash');
|
||||
const inherits = require('inherits');
|
||||
|
||||
const Client = require('../../client');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
const Formatter = require('../../formatter');
|
||||
const Transaction = require('./transaction');
|
||||
@ -215,7 +215,7 @@ assign(Client_MSSQL.prototype, {
|
||||
// Get a raw connection, called by the `pool` whenever a new
|
||||
// connection needs to be added to the pool.
|
||||
acquireRawConnection() {
|
||||
return new Promise((resolver, rejecter) => {
|
||||
return new Bluebird((resolver, rejecter) => {
|
||||
const settings = Object.assign({}, this.connectionSettings);
|
||||
settings.pool = this.mssqlPoolSettings;
|
||||
|
||||
@ -262,7 +262,7 @@ assign(Client_MSSQL.prototype, {
|
||||
// and pass that through to the stream we've sent back to the client.
|
||||
_stream(connection, obj, stream) {
|
||||
if (!obj || typeof obj === 'string') obj = { sql: obj };
|
||||
return new Promise((resolver, rejecter) => {
|
||||
return new Bluebird((resolver, rejecter) => {
|
||||
stream.on('error', (err) => {
|
||||
rejecter(err);
|
||||
});
|
||||
@ -288,7 +288,7 @@ assign(Client_MSSQL.prototype, {
|
||||
_query(connection, obj) {
|
||||
const client = this;
|
||||
if (!obj || typeof obj === 'string') obj = { sql: obj };
|
||||
return new Promise((resolver, rejecter) => {
|
||||
return new Bluebird((resolver, rejecter) => {
|
||||
const { sql } = obj;
|
||||
if (!sql) return resolver();
|
||||
const req = (connection.tx_ || connection).request();
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const Transaction = require('../../transaction');
|
||||
const { isUndefined } = require('lodash');
|
||||
const debug = require('debug')('knex:tx');
|
||||
@ -11,7 +11,7 @@ module.exports = class Transaction_MSSQL extends Transaction {
|
||||
|
||||
savepoint(conn) {
|
||||
debug('%s: savepoint at', this.txid);
|
||||
return Promise.resolve().then(() =>
|
||||
return Bluebird.resolve().then(() =>
|
||||
this.query(conn, `SAVE TRANSACTION ${this.txid}`)
|
||||
);
|
||||
}
|
||||
@ -46,7 +46,7 @@ module.exports = class Transaction_MSSQL extends Transaction {
|
||||
|
||||
rollbackTo(conn, error) {
|
||||
debug('%s: rolling backTo', this.txid);
|
||||
return Promise.resolve()
|
||||
return Bluebird.resolve()
|
||||
.then(() =>
|
||||
this.query(conn, `ROLLBACK TRANSACTION ${this.txid}`, 2, error)
|
||||
)
|
||||
@ -59,7 +59,7 @@ module.exports = class Transaction_MSSQL extends Transaction {
|
||||
acquireConnection(config) {
|
||||
const t = this;
|
||||
const configConnection = config && config.connection;
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Bluebird((resolve, reject) => {
|
||||
try {
|
||||
resolve(
|
||||
(t.outerTx ? t.outerTx.conn : null) ||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
const inherits = require('inherits');
|
||||
|
||||
const Client = require('../../client');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
const Transaction = require('./transaction');
|
||||
const QueryCompiler = require('./query/compiler');
|
||||
@ -61,7 +61,7 @@ assign(Client_MySQL.prototype, {
|
||||
// Get a raw connection, called by the `pool` whenever a new
|
||||
// connection needs to be added to the pool.
|
||||
acquireRawConnection() {
|
||||
return new Promise((resolver, rejecter) => {
|
||||
return new Bluebird((resolver, rejecter) => {
|
||||
const connection = this.driver.createConnection(this.connectionSettings);
|
||||
connection.on('error', (err) => {
|
||||
connection.__knex__disposed = err;
|
||||
@ -80,7 +80,7 @@ assign(Client_MySQL.prototype, {
|
||||
// Used to explicitly close a connection, called internally by the pool
|
||||
// when a connection times out or the pool is shutdown.
|
||||
destroyRawConnection(connection) {
|
||||
return Promise.fromCallback(connection.end.bind(connection))
|
||||
return Bluebird.fromCallback(connection.end.bind(connection))
|
||||
.catch((err) => {
|
||||
connection.__knex__disposed = err;
|
||||
})
|
||||
@ -102,7 +102,7 @@ assign(Client_MySQL.prototype, {
|
||||
_stream(connection, obj, stream, options) {
|
||||
options = options || {};
|
||||
const queryOptions = assign({ sql: obj.sql }, obj.options);
|
||||
return new Promise((resolver, rejecter) => {
|
||||
return new Bluebird((resolver, rejecter) => {
|
||||
stream.on('error', rejecter);
|
||||
stream.on('end', resolver);
|
||||
const queryStream = connection
|
||||
@ -122,7 +122,7 @@ assign(Client_MySQL.prototype, {
|
||||
// and any other necessary prep work.
|
||||
_query(connection, obj) {
|
||||
if (!obj || typeof obj === 'string') obj = { sql: obj };
|
||||
return new Promise(function(resolver, rejecter) {
|
||||
return new Bluebird(function(resolver, rejecter) {
|
||||
if (!obj.sql) {
|
||||
resolver();
|
||||
return;
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
// -------
|
||||
const inherits = require('inherits');
|
||||
const TableCompiler = require('../../../schema/tablecompiler');
|
||||
const Promise = require('bluebird');
|
||||
|
||||
const { assign } = require('lodash');
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ const { assign, map, flatten, values } = require('lodash');
|
||||
|
||||
const inherits = require('inherits');
|
||||
const Client = require('../../client');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const { bufferToString } = require('../../query/string');
|
||||
const Formatter = require('./formatter');
|
||||
|
||||
@ -79,10 +79,10 @@ assign(Client_Oracle.prototype, {
|
||||
// Get a raw connection, called by the `pool` whenever a new
|
||||
// connection needs to be added to the pool.
|
||||
acquireRawConnection() {
|
||||
return new Promise((resolver, rejecter) => {
|
||||
return new Bluebird((resolver, rejecter) => {
|
||||
this.driver.connect(this.connectionSettings, (err, connection) => {
|
||||
if (err) return rejecter(err);
|
||||
Promise.promisifyAll(connection);
|
||||
Bluebird.promisifyAll(connection);
|
||||
if (this.connectionSettings.prefetchRowCount) {
|
||||
connection.setPrefetchRowCount(
|
||||
this.connectionSettings.prefetchRowCount
|
||||
@ -96,7 +96,7 @@ assign(Client_Oracle.prototype, {
|
||||
// Used to explicitly close a connection, called internally by the pool
|
||||
// when a connection times out or the pool is shutdown.
|
||||
destroyRawConnection(connection) {
|
||||
return Promise.fromCallback(connection.close.bind(connection));
|
||||
return Bluebird.fromCallback(connection.close.bind(connection));
|
||||
},
|
||||
|
||||
// Return the database for the Oracle client.
|
||||
@ -114,7 +114,7 @@ assign(Client_Oracle.prototype, {
|
||||
},
|
||||
|
||||
_stream(connection, obj, stream, options) {
|
||||
return new Promise(function(resolver, rejecter) {
|
||||
return new Bluebird(function(resolver, rejecter) {
|
||||
stream.on('error', (err) => {
|
||||
if (isConnectionError(err)) {
|
||||
connection.__knex__disposed = err;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const Transaction = require('../../transaction');
|
||||
const { isUndefined } = require('lodash');
|
||||
const debugTx = require('debug')('knex:tx');
|
||||
@ -6,7 +6,7 @@ const debugTx = require('debug')('knex:tx');
|
||||
module.exports = class Oracle_Transaction extends Transaction {
|
||||
// disable autocommit to allow correct behavior (default is true)
|
||||
begin() {
|
||||
return Promise.resolve();
|
||||
return Bluebird.resolve();
|
||||
}
|
||||
|
||||
commit(conn, value) {
|
||||
@ -38,7 +38,7 @@ module.exports = class Oracle_Transaction extends Transaction {
|
||||
|
||||
acquireConnection(config) {
|
||||
const t = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Bluebird((resolve, reject) => {
|
||||
try {
|
||||
resolve(config.connection || t.client.acquireConnection());
|
||||
} catch (e) {
|
||||
|
||||
@ -6,7 +6,7 @@ const QueryCompiler = require('./query/compiler');
|
||||
const ColumnCompiler = require('./schema/columncompiler');
|
||||
const BlobHelper = require('./utils').BlobHelper;
|
||||
const ReturningHelper = require('./utils').ReturningHelper;
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const stream = require('stream');
|
||||
const Transaction = require('./transaction');
|
||||
const Client_Oracle = require('../oracle');
|
||||
@ -77,7 +77,7 @@ Client_Oracledb.prototype.prepBindings = function(bindings) {
|
||||
// connection needs to be added to the pool.
|
||||
Client_Oracledb.prototype.acquireRawConnection = function() {
|
||||
const client = this;
|
||||
const asyncConnection = new Promise(function(resolver, rejecter) {
|
||||
const asyncConnection = new Bluebird(function(resolver, rejecter) {
|
||||
// If external authentication dont have to worry about username/password and
|
||||
// if not need to set the username and password
|
||||
const oracleDbConfig = client.connectionSettings.externalAuth
|
||||
@ -107,7 +107,7 @@ Client_Oracledb.prototype.acquireRawConnection = function() {
|
||||
return rejecter(err);
|
||||
}
|
||||
connection.commitAsync = function() {
|
||||
return new Promise((commitResolve, commitReject) => {
|
||||
return new Bluebird((commitResolve, commitReject) => {
|
||||
if (connection.isTransaction) {
|
||||
return commitResolve();
|
||||
}
|
||||
@ -120,7 +120,7 @@ Client_Oracledb.prototype.acquireRawConnection = function() {
|
||||
});
|
||||
};
|
||||
connection.rollbackAsync = function() {
|
||||
return new Promise((rollbackResolve, rollbackReject) => {
|
||||
return new Bluebird((rollbackResolve, rollbackReject) => {
|
||||
this.rollback(function(err) {
|
||||
if (err) {
|
||||
return rollbackReject(err);
|
||||
@ -169,7 +169,7 @@ Client_Oracledb.prototype.acquireRawConnection = function() {
|
||||
};
|
||||
connection.executeAsync = function(sql, bindParams, options) {
|
||||
// Read all lob
|
||||
return new Promise(function(resultResolve, resultReject) {
|
||||
return new Bluebird(function(resultResolve, resultReject) {
|
||||
fetchAsync(sql, bindParams, options, function(err, results) {
|
||||
if (err) {
|
||||
return resultReject(err);
|
||||
@ -189,8 +189,8 @@ Client_Oracledb.prototype.acquireRawConnection = function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
Promise.each(lobs, function(lob) {
|
||||
return new Promise(function(lobResolve, lobReject) {
|
||||
Bluebird.each(lobs, function(lob) {
|
||||
return new Bluebird(function(lobResolve, lobReject) {
|
||||
readStream(lob.stream, function(err, d) {
|
||||
if (err) {
|
||||
if (results.resultSet) {
|
||||
@ -238,7 +238,7 @@ Client_Oracledb.prototype.destroyRawConnection = function(connection) {
|
||||
// Runs the query on the specified connection, providing the bindings
|
||||
// and any other necessary prep work.
|
||||
Client_Oracledb.prototype._query = function(connection, obj) {
|
||||
return new Promise(function(resolver, rejecter) {
|
||||
return new Bluebird(function(resolver, rejecter) {
|
||||
if (!obj.sql) {
|
||||
return rejecter(new Error('The query is empty'));
|
||||
}
|
||||
@ -281,12 +281,12 @@ Client_Oracledb.prototype._query = function(connection, obj) {
|
||||
}
|
||||
const rowIds = [];
|
||||
let offset = 0;
|
||||
Promise.each(obj.outBinding, function(ret, line) {
|
||||
Bluebird.each(obj.outBinding, function(ret, line) {
|
||||
offset =
|
||||
offset +
|
||||
(obj.outBinding[line - 1] ? obj.outBinding[line - 1].length : 0);
|
||||
return Promise.each(ret, function(out, index) {
|
||||
return new Promise(function(bindResolver, bindRejecter) {
|
||||
return Bluebird.each(ret, function(out, index) {
|
||||
return new Bluebird(function(bindResolver, bindRejecter) {
|
||||
if (out instanceof BlobHelper) {
|
||||
const blob = outBinds[index + offset];
|
||||
if (out.returning) {
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
const { isUndefined } = require('lodash');
|
||||
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const Transaction = require('../../transaction');
|
||||
const debugTx = require('debug')('knex:tx');
|
||||
|
||||
module.exports = class Oracle_Transaction extends Transaction {
|
||||
// disable autocommit to allow correct behavior (default is true)
|
||||
begin() {
|
||||
return Promise.resolve();
|
||||
return Bluebird.resolve();
|
||||
}
|
||||
|
||||
commit(conn, value) {
|
||||
@ -29,7 +29,7 @@ module.exports = class Oracle_Transaction extends Transaction {
|
||||
return conn
|
||||
.rollbackAsync()
|
||||
.timeout(5000)
|
||||
.catch(Promise.TimeoutError, function(e) {
|
||||
.catch(Bluebird.TimeoutError, function(e) {
|
||||
self._rejecter(e);
|
||||
})
|
||||
.then(function() {
|
||||
@ -46,7 +46,7 @@ module.exports = class Oracle_Transaction extends Transaction {
|
||||
|
||||
acquireConnection(config) {
|
||||
const t = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Bluebird(function(resolve, reject) {
|
||||
try {
|
||||
t.client
|
||||
.acquireConnection()
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
const { assign, map, extend, isArray, isString, includes } = require('lodash');
|
||||
const inherits = require('inherits');
|
||||
const Client = require('../../client');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
const QueryCompiler = require('./query/compiler');
|
||||
const ColumnCompiler = require('./schema/columncompiler');
|
||||
@ -105,7 +105,7 @@ assign(Client_PG.prototype, {
|
||||
// connection needs to be added to the pool.
|
||||
acquireRawConnection() {
|
||||
const client = this;
|
||||
return new Promise(function(resolver, rejecter) {
|
||||
return new Bluebird(function(resolver, rejecter) {
|
||||
const connection = new client.driver.Client(client.connectionSettings);
|
||||
connection.connect(function(err, connection) {
|
||||
if (err) {
|
||||
@ -133,13 +133,13 @@ assign(Client_PG.prototype, {
|
||||
// Used to explicitly close a connection, called internally by the pool
|
||||
// when a connection times out or the pool is shutdown.
|
||||
destroyRawConnection(connection) {
|
||||
return Promise.fromCallback(connection.end.bind(connection));
|
||||
return Bluebird.fromCallback(connection.end.bind(connection));
|
||||
},
|
||||
|
||||
// In PostgreSQL, we need to do a version check to do some feature
|
||||
// checking on the database.
|
||||
checkVersion(connection) {
|
||||
return new Promise(function(resolver, rejecter) {
|
||||
return new Bluebird(function(resolver, rejecter) {
|
||||
connection.query('select version();', function(err, resp) {
|
||||
if (err) return rejecter(err);
|
||||
resolver(/^PostgreSQL (.*?)( |$)/.exec(resp.rows[0].version)[1]);
|
||||
@ -164,7 +164,7 @@ assign(Client_PG.prototype, {
|
||||
setSchemaSearchPath(connection, searchPath) {
|
||||
let path = searchPath || this.searchPath;
|
||||
|
||||
if (!path) return Promise.resolve(true);
|
||||
if (!path) return Bluebird.resolve(true);
|
||||
|
||||
if (!isArray(path) && !isString(path)) {
|
||||
throw new TypeError(
|
||||
@ -189,7 +189,7 @@ assign(Client_PG.prototype, {
|
||||
|
||||
path = map(path, (schemaName) => `"${schemaName}"`).join(',');
|
||||
|
||||
return new Promise(function(resolver, rejecter) {
|
||||
return new Bluebird(function(resolver, rejecter) {
|
||||
connection.query(`set search_path to ${path}`, function(err) {
|
||||
if (err) return rejecter(err);
|
||||
resolver(true);
|
||||
@ -203,7 +203,7 @@ assign(Client_PG.prototype, {
|
||||
: require('pg-query-stream');
|
||||
const sql = obj.sql;
|
||||
|
||||
return new Promise(function(resolver, rejecter) {
|
||||
return new Bluebird(function(resolver, rejecter) {
|
||||
const queryStream = connection.query(
|
||||
new PGQueryStream(sql, obj.bindings, options)
|
||||
);
|
||||
@ -231,7 +231,7 @@ assign(Client_PG.prototype, {
|
||||
queryConfig = extend(queryConfig, obj.options);
|
||||
}
|
||||
|
||||
return new Promise(function(resolver, rejecter) {
|
||||
return new Bluebird(function(resolver, rejecter) {
|
||||
connection.query(queryConfig, function(err, response) {
|
||||
if (err) return rejecter(err);
|
||||
obj.response = response;
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
const Promise = require('bluebird');
|
||||
const Transaction = require('../../transaction');
|
||||
|
||||
module.exports = class Redshift_Transaction extends Transaction {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// SQLite3
|
||||
// -------
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
const inherits = require('inherits');
|
||||
const { isUndefined, map, assign, defaults } = require('lodash');
|
||||
@ -62,7 +62,7 @@ assign(Client_SQLite3.prototype, {
|
||||
|
||||
// Get a raw connection from the database, returning a promise with the connection object.
|
||||
acquireRawConnection() {
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Bluebird((resolve, reject) => {
|
||||
const db = new this.driver.Database(
|
||||
this.connectionSettings.filename,
|
||||
(err) => {
|
||||
@ -78,7 +78,7 @@ assign(Client_SQLite3.prototype, {
|
||||
// Used to explicitly close a connection, called internally by the pool when
|
||||
// a connection times out or the pool is shutdown.
|
||||
destroyRawConnection(connection) {
|
||||
return Promise.fromCallback(connection.close.bind(connection));
|
||||
return Bluebird.fromCallback(connection.close.bind(connection));
|
||||
},
|
||||
|
||||
// Runs the query on the specified connection, providing the bindings and any
|
||||
@ -96,7 +96,7 @@ assign(Client_SQLite3.prototype, {
|
||||
default:
|
||||
callMethod = 'all';
|
||||
}
|
||||
return new Promise(function(resolver, rejecter) {
|
||||
return new Bluebird(function(resolver, rejecter) {
|
||||
if (!connection || !connection[callMethod]) {
|
||||
return rejecter(
|
||||
new Error(`Error calling ${callMethod} on connection.`)
|
||||
@ -116,7 +116,7 @@ assign(Client_SQLite3.prototype, {
|
||||
|
||||
_stream(connection, sql, stream) {
|
||||
const client = this;
|
||||
return new Promise(function(resolver, rejecter) {
|
||||
return new Bluebird(function(resolver, rejecter) {
|
||||
stream.on('error', rejecter);
|
||||
stream.on('end', resolver);
|
||||
return client
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
// columns and changing datatypes.
|
||||
// -------
|
||||
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const {
|
||||
assign,
|
||||
uniqueId,
|
||||
@ -37,7 +37,7 @@ assign(SQLite3_DDL.prototype, {
|
||||
return this.formatter(this.tableNameRaw, (value) => value);
|
||||
},
|
||||
|
||||
getColumn: Promise.method(function(column) {
|
||||
getColumn: Bluebird.method(function(column) {
|
||||
const currentCol = find(this.pragma, (col) => {
|
||||
return (
|
||||
this.client.wrapIdentifier(col.name) ===
|
||||
@ -63,7 +63,7 @@ assign(SQLite3_DDL.prototype, {
|
||||
});
|
||||
},
|
||||
|
||||
renameTable: Promise.method(function() {
|
||||
renameTable: Bluebird.method(function() {
|
||||
return this.trx.raw(
|
||||
`ALTER TABLE "${this.tableName()}" RENAME TO "${this.alteredName}"`
|
||||
);
|
||||
@ -98,7 +98,7 @@ assign(SQLite3_DDL.prototype, {
|
||||
return function(result) {
|
||||
let batch = [];
|
||||
const ddl = this;
|
||||
return Promise.reduce(
|
||||
return Bluebird.reduce(
|
||||
result,
|
||||
function(memo, row) {
|
||||
memo++;
|
||||
@ -111,7 +111,7 @@ assign(SQLite3_DDL.prototype, {
|
||||
.then(function() {
|
||||
batch = [];
|
||||
})
|
||||
.thenReturn(memo);
|
||||
.then(() => memo);
|
||||
}
|
||||
return memo;
|
||||
},
|
||||
@ -228,7 +228,7 @@ assign(SQLite3_DDL.prototype, {
|
||||
},
|
||||
|
||||
// Boy, this is quite a method.
|
||||
renameColumn: Promise.method(function(from, to) {
|
||||
renameColumn: Bluebird.method(function(from, to) {
|
||||
return this.client.transaction(
|
||||
(trx) => {
|
||||
this.trx = trx;
|
||||
@ -251,7 +251,7 @@ assign(SQLite3_DDL.prototype, {
|
||||
})
|
||||
)
|
||||
);
|
||||
return Promise.bind(this)
|
||||
return Bluebird.bind(this)
|
||||
.then(this.createTempTable(createTable))
|
||||
.then(this.copyData)
|
||||
.then(this.dropOriginal)
|
||||
@ -271,11 +271,11 @@ assign(SQLite3_DDL.prototype, {
|
||||
);
|
||||
}),
|
||||
|
||||
dropColumn: Promise.method(function(columns) {
|
||||
dropColumn: Bluebird.method(function(columns) {
|
||||
return this.client.transaction(
|
||||
(trx) => {
|
||||
this.trx = trx;
|
||||
return Promise.all(columns.map((column) => this.getColumn(column)))
|
||||
return Bluebird.all(columns.map((column) => this.getColumn(column)))
|
||||
.bind(this)
|
||||
.then(this.getTableSql)
|
||||
.then(function(sql) {
|
||||
@ -293,7 +293,7 @@ assign(SQLite3_DDL.prototype, {
|
||||
fromPairs(columns.map((column) => [column, column]))
|
||||
)
|
||||
);
|
||||
return Promise.bind(this)
|
||||
return Bluebird.bind(this)
|
||||
.then(this.createTempTable(createTable))
|
||||
.then(this.copyData)
|
||||
.then(this.dropOriginal)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Migrator
|
||||
// -------
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const {
|
||||
differenceWith,
|
||||
each,
|
||||
@ -65,7 +65,7 @@ class Migrator {
|
||||
return migrationListResolver
|
||||
.listAllAndCompleted(this.config, this.knex)
|
||||
.tap((value) => validateMigrationList(this.config.migrationSource, value))
|
||||
.spread((all, completed) => {
|
||||
.then(([all, completed]) => {
|
||||
const migrations = getNewMigrations(
|
||||
this.config.migrationSource,
|
||||
all,
|
||||
@ -101,7 +101,7 @@ class Migrator {
|
||||
return migrationListResolver
|
||||
.listAllAndCompleted(this.config, this.knex)
|
||||
.tap((value) => validateMigrationList(this.config.migrationSource, value))
|
||||
.spread((all, completed) => {
|
||||
.then(([all, completed]) => {
|
||||
const migrationToRun = getNewMigrations(
|
||||
this.config.migrationSource,
|
||||
all,
|
||||
@ -171,7 +171,7 @@ class Migrator {
|
||||
.tap((value) => {
|
||||
return validateMigrationList(this.config.migrationSource, value);
|
||||
})
|
||||
.spread((all, completed) => {
|
||||
.then(([all, completed]) => {
|
||||
const migrationToRun = all
|
||||
.filter((migration) => {
|
||||
return completed.includes(
|
||||
@ -194,7 +194,7 @@ class Migrator {
|
||||
'*'
|
||||
),
|
||||
migrationListResolver.listAll(this.config.migrationSource),
|
||||
]).spread((db, code) => db.length - code.length);
|
||||
]).then(([db, code]) => db.length - code.length);
|
||||
}
|
||||
|
||||
// Retrieves and returns the current migration version we're on, as a promise.
|
||||
@ -307,7 +307,7 @@ class Migrator {
|
||||
return this._waterfallBatch(batchNo, migrations, direction, trx);
|
||||
})
|
||||
.tap(() => this._freeLock(trx))
|
||||
.catch((error) => {
|
||||
.catch(async (error) => {
|
||||
let cleanupReady = Promise.resolve();
|
||||
|
||||
if (error instanceof LockError) {
|
||||
@ -337,9 +337,11 @@ class Migrator {
|
||||
cleanupReady = this._freeLock(trx);
|
||||
}
|
||||
|
||||
return cleanupReady.finally(function() {
|
||||
throw error;
|
||||
});
|
||||
try {
|
||||
await cleanupReady;
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (e) {}
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -409,7 +411,7 @@ class Migrator {
|
||||
_waterfallBatch(batchNo, migrations, direction, trx) {
|
||||
const trxOrKnex = trx || this.knex;
|
||||
const { tableName, schemaName, disableTransactions } = this.config;
|
||||
let current = Promise.bind({ failed: false, failedOn: 0 });
|
||||
let current = Bluebird.bind({ failed: false, failedOn: 0 });
|
||||
const log = [];
|
||||
each(migrations, (migration) => {
|
||||
const name = this.config.migrationSource.getMigrationName(migration);
|
||||
@ -462,7 +464,7 @@ class Migrator {
|
||||
});
|
||||
});
|
||||
|
||||
return current.thenReturn([batchNo, log]);
|
||||
return current.then(() => [batchNo, log]);
|
||||
}
|
||||
|
||||
_transaction(knex, migrationContent, direction, name) {
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
// available.
|
||||
const StubMigrate = (module.exports = function() {});
|
||||
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
const noSuchMethod = Promise.method(function() {
|
||||
const noSuchMethod = Bluebird.method(function() {
|
||||
throw new Error('Migrations are not supported');
|
||||
});
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const { getTableName } = require('./table-resolver');
|
||||
const { ensureTable } = require('./table-creator');
|
||||
|
||||
@ -27,7 +27,7 @@ function listCompleted(tableName, schemaName, trxOrKnex) {
|
||||
// Gets the migration list = require(the migration directory specified in config, as well as
|
||||
// the list of completed migrations to check what should be run.
|
||||
function listAllAndCompleted(config, trxOrKnex) {
|
||||
return Promise.all([
|
||||
return Bluebird.all([
|
||||
listAll(config.migrationSource, config.loadExtensions),
|
||||
listCompleted(config.tableName, config.schemaName, trxOrKnex),
|
||||
]);
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const bluebird = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const { sortBy, filter } = require('lodash');
|
||||
|
||||
const readDirAsync = (path) =>
|
||||
bluebird.promisify(fs.readdir, { context: fs })(path);
|
||||
Bluebird.promisify(fs.readdir, { context: fs })(path);
|
||||
|
||||
const DEFAULT_LOAD_EXTENSIONS = Object.freeze([
|
||||
'.co',
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const { assign, isArray } = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
let PassThrough;
|
||||
|
||||
@ -23,7 +23,7 @@ assign(Runner.prototype, {
|
||||
run() {
|
||||
const runner = this;
|
||||
return (
|
||||
Promise.using(this.ensureConnection(), function(connection) {
|
||||
Bluebird.using(this.ensureConnection(), function(connection) {
|
||||
runner.connection = connection;
|
||||
|
||||
runner.client.emit('start', runner.builder);
|
||||
@ -79,7 +79,7 @@ assign(Runner.prototype, {
|
||||
const stream = new PassThrough({ objectMode: true });
|
||||
|
||||
let hasConnection = false;
|
||||
const promise = Promise.using(this.ensureConnection(), function(
|
||||
const promise = Bluebird.using(this.ensureConnection(), function(
|
||||
connection
|
||||
) {
|
||||
hasConnection = true;
|
||||
@ -126,7 +126,7 @@ assign(Runner.prototype, {
|
||||
// "Runs" a query, returning a promise. All queries specified by the builder are guaranteed
|
||||
// to run in sequence, and on the same connection, especially helpful when schema building
|
||||
// and dealing with foreign key constraints, etc.
|
||||
query: Promise.method(function(obj) {
|
||||
query: Bluebird.method(function(obj) {
|
||||
const { __knexUid, __knexTxId } = this.connection;
|
||||
|
||||
this.builder.emit('query', assign({ __knexUid, __knexTxId }, obj));
|
||||
@ -166,7 +166,7 @@ assign(Runner.prototype, {
|
||||
|
||||
return postProcessedResponse;
|
||||
})
|
||||
.catch(Promise.TimeoutError, (error) => {
|
||||
.catch(Bluebird.TimeoutError, (error) => {
|
||||
const { timeout, sql, bindings } = obj;
|
||||
|
||||
let cancelQuery;
|
||||
@ -178,7 +178,7 @@ assign(Runner.prototype, {
|
||||
// return the connection to the pool, it will be useless until the current operation
|
||||
// that timed out, finally finishes.
|
||||
this.connection.__knex__disposed = error;
|
||||
cancelQuery = Promise.resolve();
|
||||
cancelQuery = Bluebird.resolve();
|
||||
}
|
||||
|
||||
return cancelQuery
|
||||
@ -222,7 +222,7 @@ assign(Runner.prototype, {
|
||||
queryArray(queries) {
|
||||
return queries.length === 1
|
||||
? this.query(queries[0])
|
||||
: Promise.bind(this)
|
||||
: Bluebird.bind(this)
|
||||
.return(queries)
|
||||
.reduce(function(memo, query) {
|
||||
return this.query(query).then(function(resp) {
|
||||
@ -236,15 +236,15 @@ assign(Runner.prototype, {
|
||||
ensureConnection() {
|
||||
// Use override = require(a builder if passed
|
||||
if (this.builder._connection) {
|
||||
return Promise.resolve(this.builder._connection);
|
||||
return Bluebird.resolve(this.builder._connection);
|
||||
}
|
||||
|
||||
if (this.connection) {
|
||||
return Promise.resolve(this.connection);
|
||||
return Bluebird.resolve(this.connection);
|
||||
}
|
||||
return this.client
|
||||
.acquireConnection()
|
||||
.catch(Promise.TimeoutError, (error) => {
|
||||
.catch(Bluebird.TimeoutError, (error) => {
|
||||
if (this.builder) {
|
||||
error.sql = this.builder.sql;
|
||||
error.bindings = this.builder.bindings;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const mkdirp = require('mkdirp');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const {
|
||||
filter,
|
||||
includes,
|
||||
@ -24,11 +24,11 @@ function Seeder(knex) {
|
||||
}
|
||||
|
||||
// Runs all seed files for the given environment.
|
||||
Seeder.prototype.run = Promise.method(function(config) {
|
||||
Seeder.prototype.run = Bluebird.method(function(config) {
|
||||
this.config = this.setConfig(config);
|
||||
return this._seedData()
|
||||
.bind(this)
|
||||
.spread(function(all) {
|
||||
.then(([all]) => {
|
||||
return this._runSeeds(all);
|
||||
});
|
||||
});
|
||||
@ -37,7 +37,7 @@ Seeder.prototype.run = Promise.method(function(config) {
|
||||
Seeder.prototype.make = function(name, config) {
|
||||
this.config = this.setConfig(config);
|
||||
if (!name)
|
||||
Promise.rejected(
|
||||
Bluebird.rejected(
|
||||
new Error('A name must be specified for the generated seed')
|
||||
);
|
||||
return this._ensureFolder(config)
|
||||
@ -47,10 +47,10 @@ Seeder.prototype.make = function(name, config) {
|
||||
};
|
||||
|
||||
// Lists all available seed files as a sorted array.
|
||||
Seeder.prototype._listAll = Promise.method(function(config) {
|
||||
Seeder.prototype._listAll = Bluebird.method(function(config) {
|
||||
this.config = this.setConfig(config);
|
||||
const loadExtensions = this.config.loadExtensions;
|
||||
return Promise.promisify(fs.readdir, { context: fs })(
|
||||
return Bluebird.promisify(fs.readdir, { context: fs })(
|
||||
this._absoluteConfigDir()
|
||||
)
|
||||
.bind(this)
|
||||
@ -64,24 +64,24 @@ Seeder.prototype._listAll = Promise.method(function(config) {
|
||||
|
||||
// Gets the seed file list = require(the specified seed directory.
|
||||
Seeder.prototype._seedData = function() {
|
||||
return Promise.join(this._listAll());
|
||||
return Bluebird.join(this._listAll());
|
||||
};
|
||||
|
||||
// Ensures a folder for the seeds exist, dependent on the
|
||||
// seed config settings.
|
||||
Seeder.prototype._ensureFolder = function() {
|
||||
const dir = this._absoluteConfigDir();
|
||||
return Promise.promisify(fs.stat, { context: fs })(dir).catch(() =>
|
||||
Promise.promisify(mkdirp)(dir)
|
||||
return Bluebird.promisify(fs.stat, { context: fs })(dir).catch(() =>
|
||||
Bluebird.promisify(mkdirp)(dir)
|
||||
);
|
||||
};
|
||||
|
||||
// Run seed files, in sequence.
|
||||
Seeder.prototype._runSeeds = function(seeds) {
|
||||
return Promise.all(map(seeds, bind(this._validateSeedStructure, this)))
|
||||
return Bluebird.all(map(seeds, bind(this._validateSeedStructure, this)))
|
||||
.bind(this)
|
||||
.then(function(seeds) {
|
||||
return Promise.bind(this).then(function() {
|
||||
return Bluebird.bind(this).then(function() {
|
||||
return this._waterfallBatch(seeds);
|
||||
});
|
||||
});
|
||||
@ -101,7 +101,7 @@ Seeder.prototype._generateStubTemplate = function() {
|
||||
const stubPath =
|
||||
this.config.stub ||
|
||||
path.join(__dirname, 'stub', this.config.extension + '.stub');
|
||||
return Promise.promisify(fs.readFile, { context: fs })(stubPath).then(
|
||||
return Bluebird.promisify(fs.readFile, { context: fs })(stubPath).then(
|
||||
(stub) => template(stub.toString(), { variable: 'd' })
|
||||
);
|
||||
};
|
||||
@ -114,7 +114,7 @@ Seeder.prototype._writeNewSeed = function(name) {
|
||||
return function(tmpl) {
|
||||
if (name[0] === '-') name = name.slice(1);
|
||||
const filename = name + '.' + config.extension;
|
||||
return Promise.promisify(fs.writeFile, { context: fs })(
|
||||
return Bluebird.promisify(fs.writeFile, { context: fs })(
|
||||
path.join(dir, filename),
|
||||
tmpl(config.variables || {})
|
||||
).return(path.join(dir, filename));
|
||||
@ -125,7 +125,7 @@ Seeder.prototype._writeNewSeed = function(name) {
|
||||
Seeder.prototype._waterfallBatch = function(seeds) {
|
||||
const { knex } = this;
|
||||
const seedDirectory = this._absoluteConfigDir();
|
||||
let current = Promise.bind({ failed: false, failedOn: 0 });
|
||||
let current = Bluebird.bind({ failed: false, failedOn: 0 });
|
||||
const log = [];
|
||||
each(seeds, (seed) => {
|
||||
const name = path.join(seedDirectory, seed);
|
||||
@ -154,7 +154,7 @@ Seeder.prototype._waterfallBatch = function(seeds) {
|
||||
);
|
||||
});
|
||||
|
||||
return current.thenReturn([log]);
|
||||
return current.then(() => [log]);
|
||||
};
|
||||
|
||||
Seeder.prototype._absoluteConfigDir = function() {
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
// available.
|
||||
const StubSeed = (module.exports = function() {});
|
||||
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
const noSuchMethod = Promise.method(function() {
|
||||
const noSuchMethod = Bluebird.method(function() {
|
||||
throw new Error('Seeds are not supported');
|
||||
});
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Transaction
|
||||
// -------
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const { EventEmitter } = require('events');
|
||||
const Debug = require('debug');
|
||||
|
||||
@ -20,7 +20,7 @@ class Transaction extends EventEmitter {
|
||||
|
||||
// If there is no container provided, assume user wants to get instance of transaction and use it directly
|
||||
if (!container) {
|
||||
this.initPromise = new Promise((resolve, reject) => {
|
||||
this.initPromise = new Bluebird((resolve, reject) => {
|
||||
this.initRejectFn = reject;
|
||||
container = (transactor) => {
|
||||
resolve(transactor);
|
||||
@ -40,7 +40,7 @@ class Transaction extends EventEmitter {
|
||||
outerTx ? 'nested' : 'top level'
|
||||
);
|
||||
|
||||
this._promise = Promise.using(
|
||||
this._promise = Bluebird.using(
|
||||
this.acquireConnection(client, config, txid),
|
||||
(connection) => {
|
||||
const trxClient = (this.trxClient = makeTxClient(
|
||||
@ -64,7 +64,7 @@ class Transaction extends EventEmitter {
|
||||
try {
|
||||
result = container(transactor);
|
||||
} catch (err) {
|
||||
result = Promise.reject(err);
|
||||
result = Bluebird.reject(err);
|
||||
}
|
||||
if (result && result.then && typeof result.then === 'function') {
|
||||
result
|
||||
@ -84,7 +84,7 @@ class Transaction extends EventEmitter {
|
||||
return this._rejecter(e);
|
||||
});
|
||||
|
||||
return new Promise((resolver, rejecter) => {
|
||||
return new Bluebird((resolver, rejecter) => {
|
||||
this._resolver = resolver;
|
||||
this._rejecter = rejecter;
|
||||
});
|
||||
@ -102,7 +102,7 @@ class Transaction extends EventEmitter {
|
||||
// transactions to settle (commit or rollback) before we can start, and we
|
||||
// need to register ourselves with the parent transaction so any younger
|
||||
// siblings can wait for us to complete before they can start.
|
||||
this._previousSibling = Promise.resolve(true);
|
||||
this._previousSibling = Bluebird.resolve(true);
|
||||
if (outerTx) {
|
||||
if (outerTx._lastChild) this._previousSibling = outerTx._lastChild;
|
||||
outerTx._lastChild = this._promise;
|
||||
@ -134,7 +134,7 @@ class Transaction extends EventEmitter {
|
||||
rollback(conn, error) {
|
||||
return this.query(conn, 'ROLLBACK', 2, error)
|
||||
.timeout(5000)
|
||||
.catch(Promise.TimeoutError, () => {
|
||||
.catch(Bluebird.TimeoutError, () => {
|
||||
this._rejecter(error);
|
||||
});
|
||||
}
|
||||
@ -142,7 +142,7 @@ class Transaction extends EventEmitter {
|
||||
rollbackTo(conn, error) {
|
||||
return this.query(conn, `ROLLBACK TO SAVEPOINT ${this.txid}`, 2, error)
|
||||
.timeout(5000)
|
||||
.catch(Promise.TimeoutError, () => {
|
||||
.catch(Bluebird.TimeoutError, () => {
|
||||
this._rejecter(error);
|
||||
});
|
||||
}
|
||||
@ -183,7 +183,7 @@ class Transaction extends EventEmitter {
|
||||
// the original promise is marked completed.
|
||||
acquireConnection(client, config, txid) {
|
||||
const configConnection = config && config.connection;
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Bluebird((resolve, reject) => {
|
||||
try {
|
||||
resolve(configConnection || client.acquireConnection());
|
||||
} catch (e) {
|
||||
@ -270,7 +270,7 @@ function makeTxClient(trx, client, connection) {
|
||||
const _query = trxClient.query;
|
||||
trxClient.query = function(conn, obj) {
|
||||
const completed = trx.isCompleted();
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Bluebird(function(resolve, reject) {
|
||||
try {
|
||||
if (conn !== connection)
|
||||
throw new Error('Invalid connection for transaction query.');
|
||||
@ -284,7 +284,7 @@ function makeTxClient(trx, client, connection) {
|
||||
const _stream = trxClient.stream;
|
||||
trxClient.stream = function(conn, obj, stream, options) {
|
||||
const completed = trx.isCompleted();
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Bluebird(function(resolve, reject) {
|
||||
try {
|
||||
if (conn !== connection)
|
||||
throw new Error('Invalid connection for transaction query.');
|
||||
@ -296,10 +296,10 @@ function makeTxClient(trx, client, connection) {
|
||||
});
|
||||
};
|
||||
trxClient.acquireConnection = function() {
|
||||
return Promise.resolve(connection);
|
||||
return Bluebird.resolve(connection);
|
||||
};
|
||||
trxClient.releaseConnection = function() {
|
||||
return Promise.resolve();
|
||||
return Bluebird.resolve();
|
||||
};
|
||||
|
||||
return trxClient;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const { isNumber, isArray, chunk, flatten, assign } = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
module.exports = function batchInsert(
|
||||
client,
|
||||
@ -12,7 +12,7 @@ module.exports = function batchInsert(
|
||||
let transaction = null;
|
||||
|
||||
const getTransaction = () =>
|
||||
new Promise((resolve, reject) => {
|
||||
new Bluebird((resolve, reject) => {
|
||||
if (transaction) {
|
||||
autoTransaction = false;
|
||||
return resolve(transaction);
|
||||
@ -23,7 +23,7 @@ module.exports = function batchInsert(
|
||||
});
|
||||
|
||||
const wrapper = assign(
|
||||
new Promise((resolve, reject) => {
|
||||
new Bluebird((resolve, reject) => {
|
||||
const chunks = chunk(batch, chunkSize);
|
||||
|
||||
if (!isNumber(chunkSize) || chunkSize < 1) {
|
||||
@ -37,10 +37,10 @@ module.exports = function batchInsert(
|
||||
}
|
||||
|
||||
//Next tick to ensure wrapper functions are called if needed
|
||||
return Promise.delay(1)
|
||||
return Bluebird.delay(1)
|
||||
.then(getTransaction)
|
||||
.then((tr) => {
|
||||
return Promise.mapSeries(chunks, (items) =>
|
||||
return Bluebird.mapSeries(chunks, (items) =>
|
||||
tr(tableName).insert(items, returning)
|
||||
)
|
||||
.then((result) => {
|
||||
@ -48,7 +48,7 @@ module.exports = function batchInsert(
|
||||
|
||||
if (autoTransaction) {
|
||||
//TODO: -- Oracle tr.commit() does not return a 'thenable' !? Ugly hack for now.
|
||||
return (tr.commit(result) || Promise.resolve()).then(
|
||||
return (tr.commit(result) || Bluebird.resolve()).then(
|
||||
() => result
|
||||
);
|
||||
}
|
||||
@ -57,10 +57,10 @@ module.exports = function batchInsert(
|
||||
})
|
||||
.catch((error) => {
|
||||
if (autoTransaction) {
|
||||
return tr.rollback(error).then(() => Promise.reject(error));
|
||||
return tr.rollback(error).then(() => Bluebird.reject(error));
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
return Bluebird.reject(error);
|
||||
});
|
||||
})
|
||||
.then(resolve)
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const bluebird = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const Knex = require('../../../knex');
|
||||
const _ = require('lodash');
|
||||
const sinon = require('sinon');
|
||||
@ -476,7 +476,7 @@ module.exports = function(knex) {
|
||||
.then(function() {
|
||||
throw new Error('should not get here');
|
||||
})
|
||||
.catch(bluebird.TimeoutError, function(error) {});
|
||||
.catch(Bluebird.TimeoutError, function(error) {});
|
||||
});
|
||||
|
||||
/**
|
||||
@ -585,11 +585,11 @@ module.exports = function(knex) {
|
||||
.into('accounts');
|
||||
});
|
||||
|
||||
return bluebird
|
||||
.all([transactionReturning, transactionReturning])
|
||||
.spread(function(ret1, ret2) {
|
||||
return Promise.all([transactionReturning, transactionReturning]).then(
|
||||
([ret1, ret2]) => {
|
||||
expect(ret1).to.equal(ret2);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should pass the query context to wrapIdentifier', function() {
|
||||
|
||||
@ -7,9 +7,9 @@ const logger = require('./logger');
|
||||
const config = require('../knexfile');
|
||||
const fs = require('fs');
|
||||
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
Promise.each(Object.keys(config), function(dialectName) {
|
||||
Bluebird.each(Object.keys(config), function(dialectName) {
|
||||
return require('./suite')(logger(knex(config[dialectName])));
|
||||
});
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ const equal = require('assert').equal;
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const rimraf = require('rimraf');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const testMemoryMigrations = require('./memory-migrations');
|
||||
|
||||
module.exports = function(knex) {
|
||||
@ -170,7 +170,7 @@ module.exports = function(knex) {
|
||||
});
|
||||
|
||||
it('should return a positive number if the DB is ahead', function() {
|
||||
return Promise.all([
|
||||
return Bluebird.all([
|
||||
knex('knex_migrations')
|
||||
.returning('id')
|
||||
.insert({
|
||||
@ -192,7 +192,7 @@ module.exports = function(knex) {
|
||||
batch: 6,
|
||||
migration_time: new Date(),
|
||||
}),
|
||||
]).spread(function(migration1, migration2, migration3) {
|
||||
]).then(([migration1, migration2, migration3]) => {
|
||||
return knex.migrate
|
||||
.status({ directory: 'test/integration/migrate/test' })
|
||||
.then(function(migrationLevel) {
|
||||
@ -336,7 +336,7 @@ module.exports = function(knex) {
|
||||
// Map the table names to promises that evaluate chai expectations to
|
||||
// confirm that the table exists and the 'id' and 'name' columns exist
|
||||
// within the table
|
||||
return Promise.map(tables, function(table) {
|
||||
return Bluebird.map(tables, function(table) {
|
||||
return knex.schema.hasTable(table).then(function(exists) {
|
||||
expect(exists).to.equal(true);
|
||||
if (exists) {
|
||||
@ -385,7 +385,7 @@ module.exports = function(knex) {
|
||||
'migration_test_4_1',
|
||||
];
|
||||
|
||||
return Promise.map(expectedTables, function(table) {
|
||||
return Bluebird.map(expectedTables, function(table) {
|
||||
return knex.schema.hasTable(table).then(function(exists) {
|
||||
expect(exists).to.equal(true);
|
||||
});
|
||||
@ -397,7 +397,7 @@ module.exports = function(knex) {
|
||||
it('should delete the most recent batch from the migration log', function() {
|
||||
return knex.migrate
|
||||
.rollback({ directory: 'test/integration/migrate/test' })
|
||||
.spread(function(batchNo, log) {
|
||||
.then(([batchNo, log]) => {
|
||||
expect(batchNo).to.equal(1);
|
||||
expect(log).to.have.length(2);
|
||||
expect(log[0]).to.contain(batchNo);
|
||||
@ -410,7 +410,7 @@ module.exports = function(knex) {
|
||||
});
|
||||
|
||||
it('should drop tables as specified in the batch', function() {
|
||||
return Promise.map(tables, function(table) {
|
||||
return Bluebird.map(tables, function(table) {
|
||||
return knex.schema.hasTable(table).then(function(exists) {
|
||||
expect(!!exists).to.equal(false);
|
||||
});
|
||||
@ -445,7 +445,7 @@ module.exports = function(knex) {
|
||||
},
|
||||
true
|
||||
)
|
||||
.spread(function(batchNo, log) {
|
||||
.then(([batchNo, log]) => {
|
||||
expect(batchNo).to.equal(2);
|
||||
expect(log).to.have.length(4);
|
||||
return knex('knex_migrations')
|
||||
@ -457,7 +457,7 @@ module.exports = function(knex) {
|
||||
});
|
||||
|
||||
it('should drop tables as specified in the batch', () => {
|
||||
return Promise.map(tables, function(table) {
|
||||
return Bluebird.map(tables, function(table) {
|
||||
return knex.schema.hasTable(table).then(function(exists) {
|
||||
expect(!!exists).to.equal(false);
|
||||
});
|
||||
@ -483,7 +483,7 @@ module.exports = function(knex) {
|
||||
},
|
||||
true
|
||||
)
|
||||
.spread(function(batchNo, log) {
|
||||
.then(([batchNo, log]) => {
|
||||
expect(batchNo).to.equal(1);
|
||||
expect(log).to.have.length(2);
|
||||
|
||||
@ -502,7 +502,7 @@ module.exports = function(knex) {
|
||||
});
|
||||
|
||||
it('should drop tables as specified in the batch', () => {
|
||||
return Promise.map(tables, function(table) {
|
||||
return Bluebird.map(tables, function(table) {
|
||||
return knex.schema.hasTable(table).then(function(exists) {
|
||||
expect(!!exists).to.equal(false);
|
||||
});
|
||||
@ -672,7 +672,7 @@ module.exports = function(knex) {
|
||||
}
|
||||
|
||||
it('is not able to run two migrations in parallel when transactions are disabled', function() {
|
||||
return Promise.map(
|
||||
return Bluebird.map(
|
||||
[
|
||||
knex.migrate
|
||||
.latest({
|
||||
@ -919,7 +919,7 @@ module.exports = function(knex) {
|
||||
'migration_test_2',
|
||||
'migration_test_2_1a',
|
||||
];
|
||||
return Promise.map(tables, function(table) {
|
||||
return Bluebird.map(tables, function(table) {
|
||||
return knex.schema.hasTable(table).then(function(exists) {
|
||||
expect(exists).to.equal(true);
|
||||
if (exists) {
|
||||
|
||||
@ -18,7 +18,7 @@ module.exports = function(knex) {
|
||||
it('should run all seed files in the configured seed directory', function() {
|
||||
return knex.seed
|
||||
.run({ directory: 'test/integration/seed/test' })
|
||||
.spread(function(data) {
|
||||
.then(([data]) => {
|
||||
expect(path.basename(data[0])).to.equal('seed1.js');
|
||||
expect(path.basename(data[1])).to.equal('seed2.js');
|
||||
});
|
||||
|
||||
@ -5,7 +5,7 @@ const assert = require('assert');
|
||||
const testConfig =
|
||||
(process.env.KNEX_TEST && require(process.env.KNEX_TEST)) || {};
|
||||
const _ = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
// excluding redshift, oracle, and mssql dialects from default integrations test
|
||||
const testIntegrationDialects = (
|
||||
@ -31,7 +31,7 @@ const poolSqlite = {
|
||||
|
||||
const mysqlPool = _.extend({}, pool, {
|
||||
afterCreate: function(connection, callback) {
|
||||
Promise.promisify(connection.query, { context: connection })(
|
||||
Bluebird.promisify(connection.query, { context: connection })(
|
||||
"SET sql_mode='TRADITIONAL';",
|
||||
[]
|
||||
).then(function() {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
const tape = require('tape');
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const debug = require('debug')('knex:tests');
|
||||
|
||||
module.exports = function(tableName, knex) {
|
||||
@ -18,13 +18,13 @@ module.exports = function(tableName, knex) {
|
||||
}
|
||||
|
||||
return tape(name, function(t) {
|
||||
const disposable = Promise.resolve(true).disposer(function() {
|
||||
const disposable = Bluebird.resolve(true).disposer(function() {
|
||||
return knex.truncate(tableName).finally(function() {
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
Promise.using(disposable, function() {
|
||||
Bluebird.using(disposable, function() {
|
||||
const val = cb(t);
|
||||
if (val && typeof val.then === 'function') {
|
||||
return val.catch(function(err) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
const Promise = require('bluebird');
|
||||
const Bluebird = require('bluebird');
|
||||
const harness = require('./harness');
|
||||
const tape = require('tape');
|
||||
const JSONStream = require('JSONStream');
|
||||
@ -485,7 +485,7 @@ module.exports = function(knex) {
|
||||
|
||||
return knex
|
||||
.transaction(function(tx) {
|
||||
Promise.each(
|
||||
Bluebird.each(
|
||||
['SET join_collapse_limit to 1', 'SET enable_nestloop = off'],
|
||||
function(request) {
|
||||
return tx.raw(request);
|
||||
|
||||
@ -3,7 +3,6 @@ const expect = require('chai').expect;
|
||||
const sinon = require('sinon');
|
||||
const pgDialect = require('../../../src/dialects/postgres/index.js');
|
||||
const pg = require('pg');
|
||||
const Promise = require('bluebird');
|
||||
const _ = require('lodash');
|
||||
|
||||
describe('Postgres Unit Tests', function() {
|
||||
|
||||
@ -2,11 +2,11 @@
|
||||
/*eslint no-var:0, indent:0, max-len:0 */
|
||||
'use strict';
|
||||
|
||||
var mockFs = require('mock-fs');
|
||||
var knex = require('../../../knex');
|
||||
const mockFs = require('mock-fs');
|
||||
const knex = require('../../../knex');
|
||||
|
||||
describe('Seeder.loadExtensions', function() {
|
||||
var config = {
|
||||
const config = {
|
||||
client: 'postgres',
|
||||
connection: {
|
||||
user: 'postgres',
|
||||
@ -18,7 +18,7 @@ describe('Seeder.loadExtensions', function() {
|
||||
directory: 'test/integration/seed/seeds',
|
||||
},
|
||||
};
|
||||
var seeder;
|
||||
let seeder;
|
||||
|
||||
before(function() {
|
||||
mockFs({
|
||||
@ -69,7 +69,7 @@ describe('Seeder.loadExtensions', function() {
|
||||
});
|
||||
|
||||
describe('Seeder._waterfallBatch', function() {
|
||||
var config = {
|
||||
const config = {
|
||||
client: 'postgres',
|
||||
connection: {
|
||||
user: 'postgres',
|
||||
@ -81,7 +81,7 @@ describe('Seeder._waterfallBatch', function() {
|
||||
directory: 'test/unit/seed/test',
|
||||
},
|
||||
};
|
||||
var seeder;
|
||||
let seeder;
|
||||
|
||||
beforeEach(function() {
|
||||
seeder = knex(config).seed;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user