diff --git a/packages/sqlite-backend/SQLiteBackend.ts b/packages/sqlite-backend/SQLiteBackend.ts index 44c9f4e..b8d18f7 100644 --- a/packages/sqlite-backend/SQLiteBackend.ts +++ b/packages/sqlite-backend/SQLiteBackend.ts @@ -234,6 +234,22 @@ export class SQLiteBackend implements Backend { const rFile = await this.getFile(filepath); const file = rFile.file; + /** + * + * Simulate "upsert" by deleting anything within a block range for a file before bulk inserting! + * TODO: this should happen in a transaction + */ + + for await (const chunk of chunks) { + await this.prisma.content.deleteMany({ + where: { + offset: chunk.offset, + size: chunk.size, + fileId: file?.id, + }, + }); + } + await rawCreateMany>( this.prisma, "Content",