Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove bluebird #3650

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 17 additions & 24 deletions lib/client.js
@@ -1,5 +1,3 @@
const Bluebird = require('bluebird');

const Raw = require('./raw');
const Ref = require('./ref');
const Runner = require('./runner');
Expand Down Expand Up @@ -335,28 +333,23 @@ Object.assign(Client.prototype, {
},

// Acquire a connection from the pool.
acquireConnection() {
async acquireConnection() {
if (!this.pool) {
return Bluebird.reject(new Error('Unable to acquire a connection'));
throw new Error('Unable to acquire a connection');
}
try {
return Bluebird.try(() => this.pool.acquire().promise)
.then((connection) => {
debug('acquired connection from pool: %s', connection.__knexUid);
return connection;
})
.catch((error) => {
let convertedError = error;
if (error instanceof TimeoutError) {
convertedError = new KnexTimeoutError(
'Knex: Timeout acquiring a connection. The pool is probably full. ' +
'Are you missing a .transacting(trx) call?'
);
}
throw convertedError;
});
} catch (e) {
return Bluebird.reject(e);
const connection = await this.pool.acquire().promise;
debug('acquired connection from pool: %s', connection.__knexUid);
return connection;
} catch (error) {
let convertedError = error;
if (error instanceof TimeoutError) {
convertedError = new KnexTimeoutError(
'Knex: Timeout acquiring a connection. The pool is probably full. ' +
'Are you missing a .transacting(trx) call?'
);
}
throw convertedError;
}
},

Expand All @@ -370,14 +363,14 @@ Object.assign(Client.prototype, {
debug('pool refused connection: %s', connection.__knexUid);
}

return Bluebird.resolve();
return Promise.resolve();
},

// Destroy the current connection pool for the client.
destroy(callback) {
const maybeDestroy = this.pool && this.pool.destroy();

return Bluebird.resolve(maybeDestroy)
return Promise.resolve(maybeDestroy)
.then(() => {
this.pool = void 0;

Expand All @@ -390,7 +383,7 @@ Object.assign(Client.prototype, {
callback(err);
}

return Bluebird.reject(err);
return Promise.reject(err);
});
},

Expand Down
7 changes: 3 additions & 4 deletions lib/dialects/mssql/index.js
Expand Up @@ -4,7 +4,6 @@ const { map, flatten, values } = require('lodash');
const inherits = require('inherits');

const Client = require('../../client');
const Bluebird = require('bluebird');

const Formatter = require('../../formatter');
const Transaction = require('./transaction');
Expand Down Expand Up @@ -217,7 +216,7 @@ Object.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 Bluebird((resolver, rejecter) => {
return new Promise((resolver, rejecter) => {
const settings = Object.assign({}, this.connectionSettings);
settings.pool = this.mssqlPoolSettings;

Expand Down Expand Up @@ -264,7 +263,7 @@ Object.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 Bluebird((resolver, rejecter) => {
return new Promise((resolver, rejecter) => {
stream.on('error', (err) => {
rejecter(err);
});
Expand All @@ -290,7 +289,7 @@ Object.assign(Client_MSSQL.prototype, {
_query(connection, obj) {
const client = this;
if (!obj || typeof obj === 'string') obj = { sql: obj };
return new Bluebird((resolver, rejecter) => {
return new Promise((resolver, rejecter) => {
const { sql } = obj;
if (!sql) return resolver();
const req = (connection.tx_ || connection).request();
Expand Down
19 changes: 7 additions & 12 deletions lib/dialects/mssql/transaction.js
@@ -1,4 +1,3 @@
const Bluebird = require('bluebird');
const Transaction = require('../../transaction');
const { isUndefined } = require('lodash');
const debug = require('debug')('knex:tx');
Expand All @@ -9,11 +8,9 @@ module.exports = class Transaction_MSSQL extends Transaction {
return conn.tx_.begin().then(this._resolver, this._rejecter);
}

savepoint(conn) {
async savepoint(conn) {
debug('%s: savepoint at', this.txid);
return Bluebird.resolve().then(() =>
this.query(conn, `SAVE TRANSACTION ${this.txid}`)
);
return this.query(conn, `SAVE TRANSACTION ${this.txid}`);
}

commit(conn, value) {
Expand Down Expand Up @@ -48,21 +45,19 @@ module.exports = class Transaction_MSSQL extends Transaction {
);
}

rollbackTo(conn, error) {
async rollbackTo(conn, error) {
debug('%s: rolling backTo', this.txid);
return Bluebird.resolve()
.then(() =>
this.query(conn, `ROLLBACK TRANSACTION ${this.txid}`, 2, error)
)
.then(() => this._rejecter(error));
await this.query(conn, `ROLLBACK TRANSACTION ${this.txid}`, 2, error);

this._rejecter(error);
}

// Acquire a connection and create a disposer - either using the one passed
// via config or getting one off the client. The disposer will be called once
// the original promise is marked completed.
acquireConnection(config, cb) {
const configConnection = config && config.connection;
return new Bluebird((resolve, reject) => {
return new Promise((resolve, reject) => {
try {
resolve(
(this.outerTx ? this.outerTx.conn : null) ||
Expand Down
7 changes: 3 additions & 4 deletions lib/dialects/mysql/index.js
Expand Up @@ -4,7 +4,6 @@ const inherits = require('inherits');
const { map, defer } = require('lodash');
const { promisify } = require('util');
const Client = require('../../client');
const Bluebird = require('bluebird');

const Transaction = require('./transaction');
const QueryCompiler = require('./query/compiler');
Expand Down Expand Up @@ -61,7 +60,7 @@ Object.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 Bluebird((resolver, rejecter) => {
return new Promise((resolver, rejecter) => {
const connection = this.driver.createConnection(this.connectionSettings);
connection.on('error', (err) => {
connection.__knex__disposed = err;
Expand Down Expand Up @@ -106,7 +105,7 @@ Object.assign(Client_MySQL.prototype, {
_stream(connection, obj, stream, options) {
options = options || {};
const queryOptions = Object.assign({ sql: obj.sql }, obj.options);
return new Bluebird((resolver, rejecter) => {
return new Promise((resolver, rejecter) => {
stream.on('error', rejecter);
stream.on('end', resolver);
const queryStream = connection
Expand All @@ -126,7 +125,7 @@ Object.assign(Client_MySQL.prototype, {
// and any other necessary prep work.
_query(connection, obj) {
if (!obj || typeof obj === 'string') obj = { sql: obj };
return new Bluebird(function(resolver, rejecter) {
return new Promise(function(resolver, rejecter) {
if (!obj.sql) {
resolver();
return;
Expand Down
7 changes: 3 additions & 4 deletions lib/dialects/oracle/index.js
Expand Up @@ -5,7 +5,6 @@ const { promisify } = require('util');

const inherits = require('inherits');
const Client = require('../../client');
const Bluebird = require('bluebird');
const { bufferToString } = require('../../query/string');
const Formatter = require('./formatter');

Expand Down Expand Up @@ -80,10 +79,10 @@ Object.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 Bluebird((resolver, rejecter) => {
return new Promise((resolver, rejecter) => {
this.driver.connect(this.connectionSettings, (err, connection) => {
if (err) return rejecter(err);
Bluebird.promisifyAll(connection);
connection.executeAsync = promisify(connection.execute);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here attention needed: check all file and notice, what from connection only execute (with suffix async) is used

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I discovered earlier today that lib/dialects/oracle is actually partially-dead code. It is not used anywhere except as a parent class for lib/dialects/oracledb.

So, you might want to double-check that this method is even used by lib/dialects/oracledb. If not, then it might be easiest to just remove the entire method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easier to drop support for https://www.npmjs.com/package/oracle entirely, but this is not logical part of this merge request

if (this.connectionSettings.prefetchRowCount) {
connection.setPrefetchRowCount(
this.connectionSettings.prefetchRowCount
Expand Down Expand Up @@ -116,7 +115,7 @@ Object.assign(Client_Oracle.prototype, {
},

_stream(connection, obj, stream, options) {
return new Bluebird(function(resolver, rejecter) {
return new Promise(function(resolver, rejecter) {
stream.on('error', (err) => {
if (isConnectionError(err)) {
connection.__knex__disposed = err;
Expand Down
5 changes: 2 additions & 3 deletions lib/dialects/oracle/transaction.js
@@ -1,12 +1,11 @@
const Bluebird = require('bluebird');
const Transaction = require('../../transaction');
const { isUndefined } = require('lodash');
const debugTx = require('debug')('knex:tx');

module.exports = class Oracle_Transaction extends Transaction {
// disable autocommit to allow correct behavior (default is true)
begin() {
return Bluebird.resolve();
return Promise.resolve();
}

commit(conn, value) {
Expand Down Expand Up @@ -42,7 +41,7 @@ module.exports = class Oracle_Transaction extends Transaction {

acquireConnection(config, cb) {
const configConnection = config && config.connection;
return new Bluebird((resolve, reject) => {
return new Promise((resolve, reject) => {
try {
resolve(configConnection || this.client.acquireConnection());
} catch (e) {
Expand Down