Skip to content

Commit a6f0f2a

Browse files
committed
Use object casts in default repo update/delete
This asserts given ID exists implicitly
1 parent 3d25118 commit a6f0f2a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/core/edgedb/dto.repository.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,20 @@ export const RepoFor = <
218218
existing: Pick<Dto, 'id'>,
219219
input: UpdateShape<TResourceStatic['DB'] & {}>,
220220
): Promise<Dto> {
221-
const query = e.select(
222-
e.update(this.resource.db, () => ({
223-
filter_single: { id: existing.id } as any,
224-
set: input,
225-
})),
226-
this.hydrate as any,
221+
const object = e.cast(
222+
this.resource.db,
223+
e.cast(e.uuid, existing.id as ID),
227224
);
225+
const updated = e.update(object, () => ({
226+
set: input,
227+
}));
228+
const query = e.select(updated, this.hydrate as any);
228229
return (await this.db.run(query)) as Dto;
229230
}
230231

231232
async delete(id: ID): Promise<void> {
232-
const query = e.delete(this.resource.db, () => ({
233-
filter_single: { id } as any,
234-
}));
233+
const existing = e.cast(this.resource.db, e.cast(e.uuid, id));
234+
const query = e.delete(existing);
235235
await this.db.run(query);
236236
}
237237
}

0 commit comments

Comments
 (0)