Skip to content

Commit

Permalink
fix partial insert
Browse files Browse the repository at this point in the history
  • Loading branch information
sliterok committed Mar 10, 2024
1 parent dee2392 commit 5dc09f3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
IImportInput,
} from './types'
import { batchReduce, mergeUint8Arrays } from './helpers'
import deepmerge from 'deepmerge'

const readFile = async (dir: FileSystemDirectoryHandle, fileName: string, encoder?: IEncoder | false) => {
try {
Expand Down Expand Up @@ -253,7 +254,7 @@ export class OPFSDB<T extends IBasicRecord> {
async insert(id: string, value: T, fullRecord?: boolean) {
const oldRecord = await this.read(id)

await writeFile(this.recordsRoot, id, value, this.encoder)
await writeFile(this.recordsRoot, id, fullRecord || !oldRecord ? value : deepmerge(oldRecord, value), this.encoder)

if (!oldRecord) {
for (const key in this.trees) {
Expand Down

0 comments on commit 5dc09f3

Please sign in to comment.