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

View File

@ -48,7 +48,9 @@ class Database {
} }
getConnection(tableName) { 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) { getSchemaConnection(trx = this.connection) {