Skip to content

Commit

Permalink
fix: raw sql insert followed by in-memory find (#1381)
Browse files Browse the repository at this point in the history
* fix: raw sql sets fast path flag to false

* test

---------

Co-authored-by: typedarray <[email protected]>
  • Loading branch information
typedarray and typedarray authored Dec 28, 2024
1 parent dfae9e8 commit dae8801
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-walls-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ponder": patch
---

Fixed a bug where data inserted using raw SQL near the beginning of historical indexing was not found by subsequent `find`, `update`, or `delete` operations using the store/in-memory API.
35 changes: 35 additions & 0 deletions packages/core/src/indexing-store/historical.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,41 @@ test("sql", async (context) => {
await cleanup();
});

test("sql followed by find", async (context) => {
const schema = {
account: onchainTable("account", (p) => ({
address: p.hex().primaryKey(),
balance: p.bigint().notNull(),
})),
};

const { database, cleanup } = await setupDatabaseServices(context, {
schema,
});

const indexingStore = createHistoricalIndexingStore({
common: context.common,
database,
schema,
initialCheckpoint: encodeCheckpoint(zeroCheckpoint),
});

await indexingStore.sql
.insert(schema.account)
.values({ address: zeroAddress, balance: 10n });

const row = await indexingStore.find(schema.account, {
address: zeroAddress,
});

expect(row).toStrictEqual({
address: zeroAddress,
balance: 10n,
});

await cleanup();
});

test("onchain table", async (context) => {
const { database, cleanup } = await setupDatabaseServices(context);

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/indexing-store/historical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ export const createHistoricalIndexingStore = ({
await database.createTriggers();
await indexingStore.flush();
await database.removeTriggers();
isDatabaseEmpty = false;

const query: QueryWithTypings = { sql: _sql, params, typings };

Expand Down

0 comments on commit dae8801

Please sign in to comment.