Repository: ponder-sh/ponder (ts)

Issue:
.text().array() parsing issues with strings that have backslash literals
### Version

0.9.2

### Current behavior

Attempting to store a string with a backslash literal in a drizzle `.text().array()` column causes serialization/parsing issues. This occurs regardless of pglite or postgres backends, suggesting that the issue is within the drizzle codebase, in how they serialize `pgArray`s.

```ts
const STRING_ARRAY_VALUE = '//U_W_U\\\\'

await context.db.insert(schema.example).values({
  id: '0',
  stringArray: [STRING_ARRAY_VALUE]
})

console.log(await context.db.find(schema.example, {id: '0'}))
```

```ts
{ id: '0', stringArray: [ '//U_W_U' ], name: null }
```

and in the database the raw cell value is `{//U_W_U}`.

### Expected behavior

the string should return unchanged (`//U_W_U\\`) and the database value should represent the same

### Steps to reproduce

Check out the repo and run `pnpm dev`

### Link to repository

https://github.com/shrugs/ponder-string-array-test

### Anything else?

i'm working on tracking this down

Pull request:
fix: indexing store array parsing
Closes #1484 

Patch:
diff --git a/.changeset/eleven-bees-smell.md b/.changeset/eleven-bees-smell.md
new file mode 100644
index 00000000..7d498e2b
--- /dev/null
+++ b/.changeset/eleven-bees-smell.md
@@ -0,0 +1,5 @@
+---
+"ponder": patch
+---
+
+Fixed a bug with parsing array column values.
diff --git a/packages/core/src/indexing-store/cache.ts b/packages/core/src/indexing-store/cache.ts
index df248a92..589e58b7 100644
--- a/packages/core/src/indexing-store/cache.ts
+++ b/packages/core/src/indexing-store/cache.ts
@@ -24,7 +24,7 @@ import {
   is,
   sql,
 } from "drizzle-orm";
-import { PgTable, type PgTableWithColumns } from "drizzle-orm/pg-core";
+import { PgArray, PgTable, type PgTableWithColumns } from "drizzle-orm/pg-core";
 import { parseSqlError } from "./index.js";
 
 export type IndexingCache = {
@@ -136,6 +136,14 @@ export const normalizeColumn = (
   }
   if (column.mapToDriverValue === undefined) return value;
   try {
+    if (Array.isArray(value) && column instanceof PgArray) {
+      return value.map((v) =>
+        column.baseColumn.mapFromDriverValue(
+          column.baseColumn.mapToDriverValue(v),
+        ),
+      );
+    }
+
     return column.mapFromDriverValue(column.mapToDriverValue(value));
   } catch (e) {
     if (


Test patch:
diff --git a/packages/core/src/indexing-store/historical.test.ts b/packages/core/src/indexing-store/historical.test.ts
index c41fd15b..3ee8a84a 100644
--- a/packages/core/src/indexing-store/historical.test.ts
+++ b/packages/core/src/indexing-store/historical.test.ts
@@ -761,6 +761,52 @@ test("array", async (context) => {
   // TODO(kyle) fixed size
 });
 
+test("text array", async (context) => {
+  const { database } = await setupDatabaseServices(context);
+
+  const schema = {
+    test: onchainTable("test", (p) => ({
+      address: p.hex().primaryKey(),
+      textArray: p.text().array().notNull(),
+    })),
+  };
+
+  const indexingCache = createIndexingCache({
+    common: context.common,
+    database,
+    schemaBuild: { schema },
+    checkpoint: ZERO_CHECKPOINT_STRING,
+  });
+
+  const indexingStore = createHistoricalIndexingStore({
+    common: context.common,
+    database,
+    schemaBuild: { schema },
+    indexingCache,
+    db: database.qb.drizzle,
+  });
+
+  const STRING_ARRAY_VALUE = "//U_W_U\\\\";
+
+  await indexingStore.insert(schema.test).values({
+    address: zeroAddress,
+    textArray: [STRING_ARRAY_VALUE],
+  });
+
+  const result = await indexingStore.find(schema.test, {
+    address: zeroAddress,
+  });
+
+  expect(result).toMatchInlineSnapshot(`
+    {
+      "address": "0x0000000000000000000000000000000000000000",
+      "textArray": [
+        "//U_W_U\\\\",
+      ],
+    }
+  `);
+});
+
 test("enum", async (context) => {
   const { database } = await setupDatabaseServices(context);