Adding SQL logging capabilities.
This commit is contained in:
parent
643a46a3b7
commit
3ce00c42a2
|
@ -67,6 +67,7 @@ const environment = {
|
|||
DISABLE_RATE_LIMITING: process.env.DISABLE_RATE_LIMITING,
|
||||
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
||||
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
|
||||
ENABLE_SQL_LOGGING: process.env.ENABLE_SQL_LOGGING,
|
||||
SELF_HOSTED: process.env.SELF_HOSTED,
|
||||
HTTP_MB_LIMIT: process.env.HTTP_MB_LIMIT,
|
||||
FORKED_PROCESS_NAME: process.env.FORKED_PROCESS_NAME || "main",
|
||||
|
|
|
@ -671,6 +671,18 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
|
|||
}
|
||||
return results.length ? results : [{ [operation.toLowerCase()]: true }]
|
||||
}
|
||||
|
||||
log(query: string, values?: any[]) {
|
||||
if (!environment.ENABLE_SQL_LOGGING) {
|
||||
return
|
||||
}
|
||||
const sqlClient = this.getSqlClient()
|
||||
let string = `[SQL] [${sqlClient.toUpperCase()}] query="${query}"`
|
||||
if (values) {
|
||||
string += ` values="${values.join(", ")}"`
|
||||
}
|
||||
console.log(string)
|
||||
}
|
||||
}
|
||||
|
||||
export default SqlQueryBuilder
|
||||
|
|
|
@ -329,6 +329,7 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
|||
operation === Operation.CREATE
|
||||
? `${query.sql}; SELECT SCOPE_IDENTITY() AS id;`
|
||||
: query.sql
|
||||
this.log(sql, query.bindings)
|
||||
return await request.query(sql)
|
||||
} catch (err: any) {
|
||||
let readableMessage = getReadableErrorMessage(
|
||||
|
|
|
@ -261,6 +261,7 @@ class MySQLIntegration extends Sql implements DatasourcePlus {
|
|||
const bindings = opts?.disableCoercion
|
||||
? baseBindings
|
||||
: bindingTypeCoerce(baseBindings)
|
||||
this.log(query.sql, bindings)
|
||||
// Node MySQL is callback based, so we must wrap our call in a promise
|
||||
const response = await this.client!.query(query.sql, bindings)
|
||||
return response[0]
|
||||
|
|
|
@ -368,6 +368,7 @@ class OracleIntegration extends Sql implements DatasourcePlus {
|
|||
const options: ExecuteOptions = { autoCommit: true }
|
||||
const bindings: BindParameters = query.bindings || []
|
||||
|
||||
this.log(query.sql, bindings)
|
||||
return await connection.execute<T>(query.sql, bindings, options)
|
||||
} finally {
|
||||
if (connection) {
|
||||
|
|
|
@ -262,7 +262,9 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
|||
}
|
||||
}
|
||||
try {
|
||||
return await client.query(query.sql, query.bindings || [])
|
||||
const bindings = query.bindings || []
|
||||
this.log(query.sql, bindings)
|
||||
return await client.query(query.sql, bindings)
|
||||
} catch (err: any) {
|
||||
await this.closeConnection()
|
||||
let readableMessage = getReadableErrorMessage(
|
||||
|
|
Loading…
Reference in New Issue