Database: Fix 'update' queries for PG-derived DBs

PG/Cockroach do not support 'limit' clauses in update queries, so this has to be edited out where applicable.
This commit is contained in:
Mia 2025-04-16 13:42:37 -05:00
parent 1cec1eaa36
commit 37b5fbcd1d

View File

@ -291,7 +291,11 @@ export class DatabaseTable<Row, DB extends Database> {
}
update(primaryKey: BasicSQLValue, data: PartialOrSQL<Row>) {
if (!this.primaryKeyName) throw new Error(`Cannot update() without a single-column primary key`);
return this.updateAll(data)`WHERE "${this.primaryKeyName}" = ${primaryKey} LIMIT 1`;
// cockroach/pg do not support limit in update queries so we have to case this
return this.updateAll(data)`
WHERE "${this.primaryKeyName}" = ${primaryKey}
${this.db.type === 'mysql' ? SQL` LIMIT 1` : ''}
`;
}
}