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

Seq6-custom #7

Merged
merged 4 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/dialects/abstract/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ class AbstractQuery {
_logQuery(sql, debugContext, parameters) {
const { connection, options } = this;
const benchmark = this.sequelize.options.benchmark || options.benchmark;

const instanceType = connection.queryType === 'read' ? 'replica' : 'primary';
const instanceTypeMessage = `on ${instanceType} DB`;

const logQueryParameters = this.sequelize.options.logQueryParameters || options.logQueryParameters;
const startTime = Date.now();
let logParameter = '';
Expand All @@ -355,7 +359,8 @@ class AbstractQuery {
const afterMsg = `Executed ${fmt}`;
debugContext(afterMsg);
if (benchmark) {
this.sequelize.log(afterMsg, Date.now() - startTime, options);
const elapsedTime = Date.now() - startTime;
this.sequelize.log(`Executed ${elapsedTime > this.sequelize.options.queryThreshold ? 'SLOW QUERY ' : ''} (${instanceTypeMessage}, ${fmt}`, elapsedTime, options);
}
};
}
Expand Down
3 changes: 3 additions & 0 deletions lib/dialects/sqlite/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ class Query extends AbstractQuery {
return new sequelizeErrors.TimeoutError(err, { stack: errStack });

default:
if (err.message && err.message.includes("SQLITE_ERROR: no such table")) {
console.log(err.sql);
}
return new sequelizeErrors.DatabaseError(err, { stack: errStack });
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const hookTypes = {
beforeBulkSync: { params: 1 },
afterBulkSync: { params: 1 },
beforeQuery: { params: 2 },
afterQuery: { params: 2 }
afterQuery: { params: 2 },
beforeGetConnection: {params: 2}
};
exports.hooks = hookTypes;

Expand Down
4 changes: 3 additions & 1 deletion lib/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,9 @@ class Sequelize {

checkTransaction();

const connection = await (options.transaction ? options.transaction.connection : this.connectionManager.getConnection(options));
const connection = await (options.transaction ?
options.transaction.connection :
this.runHooks('beforeGetConnection', options, sql).then(() => this.connectionManager.getConnection(options)));
const query = new this.dialect.Query(connection, this, options);

try {
Expand Down