mirror of
https://github.com/knex/knex.git
synced 2025-12-28 15:38:41 +00:00
Remove Bluebird.try (#3263)
This commit is contained in:
parent
501d58a6d9
commit
ab6a3047aa
@ -86,13 +86,11 @@ if (POSTINSTALL_BUILD_CWD !== CWD) {
|
||||
})
|
||||
.value()
|
||||
.join(' ');
|
||||
|
||||
Promise.try(function() {
|
||||
if (!_.isEmpty(installArgs)) {
|
||||
console.log('Installing dependencies');
|
||||
return exec('npm install ' + installArgs, opts);
|
||||
}
|
||||
})
|
||||
const needsDepInstallation = !_.isEmpty(installArgs);
|
||||
const dependenciesInstalledQ = needsDepInstallation
|
||||
? exec('npm install ' + installArgs, opts)
|
||||
: Promise.resolve();
|
||||
dependenciesInstalledQ
|
||||
.then(function(stdout, stderr) {
|
||||
console.log('✓');
|
||||
// Don't need the flag anymore as `postinstall` was already run.
|
||||
|
||||
@ -304,17 +304,20 @@ assign(Client.prototype, {
|
||||
if (!this.pool) {
|
||||
return Promise.reject(new Error('Unable to acquire a connection'));
|
||||
}
|
||||
|
||||
return Promise.try(() => this.pool.acquire().promise)
|
||||
.tap((connection) => {
|
||||
debug('acquired connection from pool: %s', connection.__knexUid);
|
||||
})
|
||||
.catch(TimeoutError, () => {
|
||||
throw new Promise.TimeoutError(
|
||||
'Knex: Timeout acquiring a connection. The pool is probably full. ' +
|
||||
'Are you missing a .transacting(trx) call?'
|
||||
);
|
||||
});
|
||||
try {
|
||||
return Promise.try(() => this.pool.acquire().promise)
|
||||
.tap((connection) => {
|
||||
debug('acquired connection from pool: %s', connection.__knexUid);
|
||||
})
|
||||
.catch(TimeoutError, () => {
|
||||
throw new Promise.TimeoutError(
|
||||
'Knex: Timeout acquiring a connection. The pool is probably full. ' +
|
||||
'Are you missing a .transacting(trx) call?'
|
||||
);
|
||||
});
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
},
|
||||
|
||||
// Releases a connection back to the connection pool,
|
||||
|
||||
@ -59,12 +59,16 @@ module.exports = class Transaction_MSSQL extends Transaction {
|
||||
acquireConnection(config) {
|
||||
const t = this;
|
||||
const configConnection = config && config.connection;
|
||||
return Promise.try(() => {
|
||||
return (
|
||||
(t.outerTx ? t.outerTx.conn : null) ||
|
||||
configConnection ||
|
||||
t.client.acquireConnection()
|
||||
);
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
resolve(
|
||||
(t.outerTx ? t.outerTx.conn : null) ||
|
||||
configConnection ||
|
||||
t.client.acquireConnection()
|
||||
);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
})
|
||||
.tap(function(conn) {
|
||||
conn.__knexTxId = t.txid;
|
||||
|
||||
@ -85,16 +85,18 @@ assign(TableCompiler_MySQL.prototype, {
|
||||
.getFKRefs(runner)
|
||||
.get(0)
|
||||
.then((refs) =>
|
||||
Promise.try(function() {
|
||||
if (!refs.length) {
|
||||
return;
|
||||
new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (!refs.length) {
|
||||
resolve();
|
||||
}
|
||||
resolve(compiler.dropFKRefs(runner, refs));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
return compiler.dropFKRefs(runner, refs);
|
||||
})
|
||||
.then(function() {
|
||||
let sql = `alter table ${table} change ${wrapped} ${
|
||||
column.Type
|
||||
}`;
|
||||
let sql = `alter table ${table} change ${wrapped} ${column.Type}`;
|
||||
|
||||
if (String(column.Null).toUpperCase() !== 'YES') {
|
||||
sql += ` NOT NULL`;
|
||||
|
||||
@ -38,7 +38,13 @@ module.exports = class Oracle_Transaction extends Transaction {
|
||||
|
||||
acquireConnection(config) {
|
||||
const t = this;
|
||||
return Promise.try(() => config.connection || t.client.acquireConnection())
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
resolve(config.connection || t.client.acquireConnection());
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
})
|
||||
.then((connection) => {
|
||||
connection.__knexTxId = this.txid;
|
||||
|
||||
|
||||
@ -46,12 +46,19 @@ module.exports = class Oracle_Transaction extends Transaction {
|
||||
|
||||
acquireConnection(config) {
|
||||
const t = this;
|
||||
return Promise.try(function() {
|
||||
return t.client.acquireConnection().then(function(cnx) {
|
||||
cnx.__knexTxId = t.txid;
|
||||
cnx.isTransaction = true;
|
||||
return cnx;
|
||||
});
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
t.client
|
||||
.acquireConnection()
|
||||
.then(function(cnx) {
|
||||
cnx.__knexTxId = t.txid;
|
||||
cnx.isTransaction = true;
|
||||
resolve(cnx);
|
||||
})
|
||||
.catch(reject);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
}).disposer(function(connection) {
|
||||
debugTx('%s: releasing connection', t.txid);
|
||||
connection.isTransaction = false;
|
||||
|
||||
@ -133,10 +133,13 @@ class Migrator {
|
||||
// Rollback the last "batch", or all, of migrations that were run.
|
||||
rollback(config, all = false) {
|
||||
this._disableProcessing();
|
||||
return Promise.try(() => {
|
||||
this.config = getMergedConfig(config, this.config);
|
||||
|
||||
return migrationListResolver
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
this.config = getMergedConfig(config, this.config);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
migrationListResolver
|
||||
.listAllAndCompleted(this.config, this.knex)
|
||||
.tap((value) =>
|
||||
validateMigrationList(this.config.migrationSource, value)
|
||||
@ -154,7 +157,8 @@ class Migrator {
|
||||
})
|
||||
.then((migrations) => {
|
||||
return this._runBatch(migrations, 'down');
|
||||
});
|
||||
})
|
||||
.then(resolve, reject);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -183,7 +183,13 @@ class Transaction extends EventEmitter {
|
||||
// the original promise is marked completed.
|
||||
acquireConnection(client, config, txid) {
|
||||
const configConnection = config && config.connection;
|
||||
return Promise.try(() => configConnection || client.acquireConnection())
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
resolve(configConnection || client.acquireConnection());
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
})
|
||||
.then(function(connection) {
|
||||
connection.__knexTxId = txid;
|
||||
|
||||
@ -264,21 +270,29 @@ function makeTxClient(trx, client, connection) {
|
||||
const _query = trxClient.query;
|
||||
trxClient.query = function(conn, obj) {
|
||||
const completed = trx.isCompleted();
|
||||
return Promise.try(function() {
|
||||
if (conn !== connection)
|
||||
throw new Error('Invalid connection for transaction query.');
|
||||
if (completed) completedError(trx, obj);
|
||||
return _query.call(trxClient, conn, obj);
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
if (conn !== connection)
|
||||
throw new Error('Invalid connection for transaction query.');
|
||||
if (completed) completedError(trx, obj);
|
||||
resolve(_query.call(trxClient, conn, obj));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
const _stream = trxClient.stream;
|
||||
trxClient.stream = function(conn, obj, stream, options) {
|
||||
const completed = trx.isCompleted();
|
||||
return Promise.try(function() {
|
||||
if (conn !== connection)
|
||||
throw new Error('Invalid connection for transaction query.');
|
||||
if (completed) completedError(trx, obj);
|
||||
return _stream.call(trxClient, conn, obj, stream, options);
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
if (conn !== connection)
|
||||
throw new Error('Invalid connection for transaction query.');
|
||||
if (completed) completedError(trx, obj);
|
||||
resolve(_stream.call(trxClient, conn, obj, stream, options));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
trxClient.acquireConnection = function() {
|
||||
|
||||
2
types/index.d.ts
vendored
2
types/index.d.ts
vendored
@ -315,7 +315,7 @@ interface Knex<TRecord extends {} = any, TResult = any[]>
|
||||
config?: any
|
||||
): () => Promise<Knex.Transaction>;
|
||||
transaction(
|
||||
transactionScope?: undefined | null,
|
||||
transactionScope?: null,
|
||||
config?: any
|
||||
): Promise<Knex.Transaction>;
|
||||
transaction<T>(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user