Skip to content

Commit 62a61da

Browse files
jakubriedljamesgpearce
authored andcommitted
[pagination] Scope partial delete
1 parent 1eb4fe0 commit 62a61da

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/persisters/common/database/commands.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,11 @@ export const getCommandFunctions = (
239239
DELETE_FROM +
240240
escapeId(tableName) +
241241
WHERE +
242+
' (' +
242243
escapeId(rowIdColumnName) +
243-
'=$1',
244+
'=$1) AND (' +
245+
getWhereCondition(tableName, condition) +
246+
')',
244247
[rowId],
245248
);
246249
} else if (!arrayIsEmpty(settingColumnNames)) {
@@ -290,7 +293,7 @@ export const getCommandFunctions = (
290293
WHERE +
291294
escapeId(rowIdColumnName) +
292295
`NOT IN(${getPlaceholders(deleteRowIds)}) ` +
293-
`AND${getWhereCondition(tableName, condition)}`,
296+
`AND (${getWhereCondition(tableName, condition)})`,
294297
deleteRowIds,
295298
);
296299
} else if (collHas(schemaMap, tableName)) {

test/unit/persisters/database/tabular.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,8 @@ describe.each(Object.entries(ALL_VARIANTS))(
12651265
'INSERT INTO"t2"("_id","c1")VALUES($1,$2)ON CONFLICT("_id")DO UPDATE SET"c1"=excluded."c1"',
12661266
['r1', encodedValue(1)],
12671267
],
1268-
['DELETE FROM"t1"WHERE"_id"NOT IN($1,$2) AND true', ['r1', 'r2']],
1269-
['DELETE FROM"t2"WHERE"_id"NOT IN($1) AND true', ['r1']],
1268+
['DELETE FROM"t1"WHERE"_id"NOT IN($1,$2) AND ( true)', ['r1', 'r2']],
1269+
['DELETE FROM"t2"WHERE"_id"NOT IN($1) AND ( true)', ['r1']],
12701270
[
12711271
'CREATE TABLE"tinybase_values"("_id"' +
12721272
columnType +
@@ -1281,7 +1281,7 @@ describe.each(Object.entries(ALL_VARIANTS))(
12811281
'INSERT INTO"tinybase_values"("_id","v1","v2")VALUES($1,$2,$3)ON CONFLICT("_id")DO UPDATE SET"v1"=excluded."v1","v2"=excluded."v2"',
12821282
['_', encodedValue(1), encodedValue(2)],
12831283
],
1284-
['DELETE FROM"tinybase_values"WHERE"_id"NOT IN($1) AND true', ['_']],
1284+
['DELETE FROM"tinybase_values"WHERE"_id"NOT IN($1) AND ( true)', ['_']],
12851285
['END', undefined],
12861286
]);
12871287
});
@@ -1560,7 +1560,7 @@ describe.each(Object.entries(ALL_VARIANTS))(
15601560
});
15611561
sqlCheck(sqlLogs, [
15621562
['BEGIN', undefined],
1563-
['DELETE FROM"t1"WHERE"_id"=$1', ['r1']],
1563+
['DELETE FROM"t1"WHERE ("_id"=$1) AND ( true)', ['r1']],
15641564
['END', undefined],
15651565
]);
15661566
});

0 commit comments

Comments
 (0)