Database: Revert syntax for multiline queries

As explicitly documented in `CONTRIBUTING.md`, we are against multiline
template strings. While I see the advantages in readability for the
multiline approach, I'd rather not send extraneous whitespace to the
database.
This commit is contained in:
Guangcong Luo 2025-08-05 22:11:43 -07:00
parent 4a8341586a
commit f770b255f3

View File

@ -300,11 +300,9 @@ export class DatabaseTable<Row, DB extends Database> {
}
upsert(partialRow: PartialOrSQL<Row>, partialUpdate = partialRow, where?: SQLStatement) {
if (this.db.type === 'pg') {
return this.queryExec()`
INSERT INTO "${this.name}" (${partialRow as any})
ON CONFLICT (${this.primaryKeyName}) DO UPDATE
SET ${partialUpdate as any} ${where}
`;
return this.queryExec(
)`INSERT INTO "${this.name}" (${partialRow as any}) ON CONFLICT (${this.primaryKeyName
}) DO UPDATE SET ${partialUpdate as any} ${where}`;
}
return this.queryExec(
)`INSERT INTO "${this.name}" (${partialRow as any}) ON DUPLICATE KEY UPDATE ${partialUpdate as any} ${where}`;
@ -312,10 +310,9 @@ export class DatabaseTable<Row, DB extends Database> {
replace(partialRow: PartialOrSQL<Row>, where?: SQLStatement) {
if (this.db.type === 'pg') {
if (!this.primaryKeyName) throw new Error(`Cannot replace() without a single-column primary key`);
return this.queryExec()`
INSERT INTO "${this.name}" (${partialRow as any})
ON CONFLICT ("${this.primaryKeyName}") DO UPDATE SET ${partialRow as any} ${where}
`;
return this.queryExec(
)`INSERT INTO "${this.name}" (${partialRow as any}) ON CONFLICT ("${this.primaryKeyName
}") DO UPDATE SET ${partialRow as any} ${where}`;
}
return this.queryExec()`REPLACE INTO "${this.name}" (${partialRow as SQLValue}) ${where}`;
}