Skip to content

Commit

Permalink
fix: insert empty records on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaaa committed Jan 5, 2024
1 parent 40c4fd8 commit 6d94c98
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/store-sync/src/postgres-decoded/createStorageAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,33 @@ export async function createStorageAdapter<TConfig extends StoreConfig = StoreCo
})
.execute();
} else if (log.eventName === "Store_DeleteRecord") {
const value = decodeValueArgs(table.valueSchema, {
staticData: "0x",
encodedLengths: "0x",
dynamicData: "0x",
});

debug("deleting record", {
namespace: table.namespace,
name: table.name,
key,
});

await tx
.delete(sqlTable)
.where(and(eq(sqlTable.__keyBytes, keyBytes), eq(sqlTable.__lastUpdatedBlockNumber, blockNumber)))
.insert(sqlTable)
.values({
__keyBytes: keyBytes,
__lastUpdatedBlockNumber: blockNumber,
...key,
...value,
})
.onConflictDoUpdate({
target: [sqlTable.__keyBytes, sqlTable.__lastUpdatedBlockNumber],
set: {
__lastUpdatedBlockNumber: blockNumber,
...value,
},
})
.execute();
}
}
Expand Down

0 comments on commit 6d94c98

Please sign in to comment.