support get and delete on documents

This commit is contained in:
Morten Olsen
2025-09-09 18:39:11 +02:00
parent 6b8bae55da
commit c59c9487e6

View File

@@ -26,6 +26,36 @@ class DocumentsService extends EventEmitter<DocumentEvents> {
this.#services = services;
}
public get = async (uri: string, type: string) => {
const db = await this.#services.get(DatabaseService).getDb();
const [document] = await db<TableRow['document']>(tableNames.documents)
.where({
uri,
type,
})
.limit(1);
return document;
};
public delete = async (uri: string, type: string) => {
const db = await this.#services.get(DatabaseService).getDb();
const [document] = await db<TableRow['document']>(tableNames.documents)
.where({
uri,
type,
})
.limit(1);
if (!document) {
return;
}
const toDelete: Document = {
...document,
deletedAt: new Date().toISOString(),
};
await db(tableNames.documents).where({ uri, type }).update(toDelete);
this.emit('upsert', { action: 'delete', document: toDelete });
};
public upsert = async (document: DocumentUpsert) => {
const db = await this.#services.get(DatabaseService).getDb();
const [current] = await db<TableRow['document']>(tableNames.documents)