Skip to content

Commit

Permalink
Merge pull request #5 from divyenduz/fix_write_upsert
Browse files Browse the repository at this point in the history
fix: write upsert
  • Loading branch information
divyenduz authored Oct 21, 2023
2 parents 7f9eb00 + 22ba73c commit bfe42f9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/sqlite-backend/SQLiteBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Omit<Content, "id">>(
this.prisma,
"Content",
Expand Down

0 comments on commit bfe42f9

Please sign in to comment.