fix(entity-manager): use db.connection for .raw()

chore(database): revert getConnection()
This commit is contained in:
Jamie Howard 2022-11-16 09:34:08 +00:00
parent 5553538c18
commit 4b1f8101e6
2 changed files with 14 additions and 7 deletions

View File

@ -226,8 +226,7 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction
// https://github.com/knex/knex/issues/2504
switch (strapi.db.dialect.client) {
case 'mysql':
await db
.getConnection()
await db.connection
.raw(
`UPDATE
?? as a,
@ -242,9 +241,14 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction
)
.transacting(trx);
break;
default:
await db
.getConnection()
default: {
const schemaName = db.connection.getSchemaName();
let joinTableName = joinTable.name;
if (schemaName) {
joinTableName = `${schemaName}.${joinTableName}`;
}
await db.connection
.raw(
`UPDATE ?? as a
SET ${update.join(', ')}
@ -254,9 +258,10 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction
WHERE ${where.join(' OR ')}
) AS b
WHERE b.id = a.id`,
[joinTable.name, ...updateBinding, ...selectBinding, joinTable.name, ...whereBinding]
[joinTableName, ...updateBinding, ...selectBinding, joinTableName, ...whereBinding]
)
.transacting(trx);
}
/*
`UPDATE :joinTable: as a
SET :orderColumn: = b.src_order, :inverseOrderColumn: = b.inv_order

View File

@ -48,7 +48,9 @@ class Database {
}
getConnection(tableName) {
return tableName ? this.connection(tableName) : this.connection;
const schema = this.connection.getSchemaName();
const connection = tableName ? this.connection(tableName) : this.connection;
return schema ? connection.withSchema(schema) : connection;
}
getSchemaConnection(trx = this.connection) {