Skip to content

Commit

Permalink
feat(store-sync): bool array column types for decoded indexer (#2283)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
  • Loading branch information
yonadaaa and holic committed Feb 20, 2024
1 parent 669fa43 commit 4e445a1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-numbers-design.md
@@ -0,0 +1,5 @@
---
"@latticexyz/store-sync": patch
---

Moved boolean array types to use array column types (instead of JSON columns) for the Postgres decoded indexer
15 changes: 13 additions & 2 deletions packages/store-sync/src/postgres-decoded/buildColumn.ts
@@ -1,7 +1,16 @@
import { boolean, text } from "drizzle-orm/pg-core";
import { SchemaAbiType } from "@latticexyz/schema-type";
import { assertExhaustive } from "@latticexyz/common/utils";
import { asAddress, asBigInt, asBigIntArray, asHex, asJson, asNumber, asNumberArray } from "../postgres/columnTypes";
import {
asAddress,
asBigInt,
asBigIntArray,
asBoolArray,
asHex,
asJson,
asNumber,
asNumberArray,
} from "../postgres/columnTypes";

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function buildColumn(name: string, schemaAbiType: SchemaAbiType) {
Expand Down Expand Up @@ -124,6 +133,9 @@ export function buildColumn(name: string, schemaAbiType: SchemaAbiType) {
case "address":
return asAddress(name);

case "bool[]":
return asBoolArray(name);

case "uint8[]":
case "uint16[]":
case "uint24[]":
Expand Down Expand Up @@ -233,7 +245,6 @@ export function buildColumn(name: string, schemaAbiType: SchemaAbiType) {
case "bytes30[]":
case "bytes31[]":
case "bytes32[]":
case "bool[]":
return asJson(name);

// TODO: normalize like address column type
Expand Down
Expand Up @@ -52,7 +52,7 @@ describe("createStorageAdapter", async () => {
{
"blockNumber": 20n,
"chainId": 31337,
"version": "0.0.5",
"version": "0.0.6",
},
]
`);
Expand Down
14 changes: 14 additions & 0 deletions packages/store-sync/src/postgres/columnTypes.ts
Expand Up @@ -73,6 +73,20 @@ export const asAddress = (name: string) =>
},
})(name);

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const asBoolArray = (name: string) =>
customType<{ data: boolean[]; driverData: string[] }>({
dataType() {
return "bool[]";
},
toDriver(data: boolean[]): string[] {
return data.map((datum) => String(datum));
},
fromDriver(driverData: string[]): boolean[] {
return driverData.map((datum) => Boolean(datum));
},
})(name);

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const asNumberArray = (name: string, columnType: string) =>
customType<{ data: number[]; driverData: string[] }>({
Expand Down
Expand Up @@ -50,7 +50,7 @@ describe("createStorageAdapter", async () => {
{
"blockNumber": 20n,
"chainId": 31337,
"version": "0.0.5",
"version": "0.0.6",
},
]
`);
Expand Down
2 changes: 1 addition & 1 deletion packages/store-sync/src/postgres/version.ts
@@ -1 +1 @@
export const version = "0.0.5";
export const version = "0.0.6";

0 comments on commit 4e445a1

Please sign in to comment.