Skip to content

Commit fb80344

Browse files
committed
Cleanup code
1 parent 01898d6 commit fb80344

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/literest/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ export class LiteREST {
186186
}
187187

188188
const tableName = this.sanitizeIdentifier(pathParts.length === 1 ? pathParts[0] : pathParts[1]);
189-
const schemaName = this.sanitizeIdentifier(pathParts[0]) //pathParts.length === 1 ? undefined : this.sanitizeIdentifier(pathParts[0])
190-
const id = pathParts.length === 3 ? pathParts[2] : undefined; // pathParts.length === 3 ? pathParts[1] : pathParts[2];
189+
const schemaName = this.sanitizeIdentifier(pathParts[0]);
190+
const id = pathParts.length === 3 ? pathParts[2] : undefined;
191191
const body = ['POST', 'PUT', 'PATCH'].includes(liteRequest.method) ? await liteRequest.json() : undefined;
192192

193193
return {
@@ -409,7 +409,13 @@ export class LiteREST {
409409
const pkColumns = await this.getPrimaryKeyColumns(tableName, schemaName);
410410

411411
let data: any = {}
412-
data[pkColumns[0]] = id
412+
413+
// Currently the DELETE only works with single primary key tables.
414+
if (pkColumns.length) {
415+
const firstPK = pkColumns[0]
416+
data[firstPK] = id
417+
}
418+
413419
const { conditions: pkConditions, params: pkParams, error } = this.getPrimaryKeyConditions(pkColumns, id, data, new URLSearchParams());
414420

415421
if (error) {

0 commit comments

Comments
 (0)