Skip to content

Commit 0812178

Browse files
authored
fix(explorer): return empty array for empty results (sqlite indexer) (#3469)
1 parent dab0d08 commit 0812178

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

.changeset/thin-pianos-repair.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/explorer": patch
3+
---
4+
5+
The Explorer now returns an empty array for empty results, instead of throwing an error, when using the local indexer.

packages/explorer/src/app/(explorer)/api/sqlite-indexer/route.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ export async function POST(request: Request) {
1919
const result = [];
2020
for (const { query } of queries) {
2121
const data = (await db?.prepare(query).all()) as SqliteTable;
22-
if (!data || !data[0]) {
23-
throw new Error("No data found");
22+
23+
if (!data || !Array.isArray(data)) {
24+
throw new Error("Invalid query result");
25+
}
26+
27+
if (data.length === 0) {
28+
result.push([]);
29+
continue;
30+
}
31+
32+
if (!data[0]) {
33+
throw new Error("Invalid row data");
2434
}
2535

2636
const columns = Object.keys(data[0]).map((key) => key.replaceAll("_", "").toLowerCase());

0 commit comments

Comments
 (0)