Skip to content

Commit

Permalink
Merge pull request #1245 from ponder-sh/kjs/fix-default
Browse files Browse the repository at this point in the history
fix: default columns
  • Loading branch information
kyscott18 authored Nov 15, 2024
2 parents a80e683 + 7f4f456 commit 3f5029e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-snails-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

Fixed a bug with the `.default()` column modifier causing the value to be undefined.
4 changes: 2 additions & 2 deletions packages/core/src/indexing-store/historical.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ test("default", async (context) => {
const schema = {
account: onchainTable("account", (p) => ({
address: p.hex().primaryKey(),
balance: p.bigint().default(10n),
balance: p.integer().default(0),
})),
};

Expand All @@ -573,7 +573,7 @@ test("default", async (context) => {
address: zeroAddress,
});

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

await cleanup();
});
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/indexing-store/historical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ export const createHistoricalIndexingStore = ({
if (type === EntryType.UPDATE && column.onUpdateFn) {
return column.onUpdateFn();
}
if (column.default) return column.default;
if (column.defaultFn) return column.defaultFn();
if (column.onUpdateFn) return column.onUpdateFn();
if (column.default !== undefined) return column.default;
if (column.defaultFn !== undefined) return column.defaultFn();
if (column.onUpdateFn !== undefined) return column.onUpdateFn();

// TODO(kyle) is it an invariant that it doesn't get here

Expand Down

0 comments on commit 3f5029e

Please sign in to comment.