Skip to content

Commit 0facee0

Browse files
authored
fix(explorer): format default sql query (#3363)
1 parent 3168f1f commit 0facee0

File tree

4 files changed

+9
-377
lines changed

4 files changed

+9
-377
lines changed

.changeset/hip-spies-wave.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+
When accessing a new table in Explore tab, the SQL editor now encloses all column names in double quotes in order to prevent invalid queries.

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/Explorer.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { indexerForChainId } from "../../../../utils/indexerForChainId";
1212
import { SQLEditor } from "./SQLEditor";
1313
import { TableSelector } from "./TableSelector";
1414
import { TablesViewer } from "./TablesViewer";
15-
import { postgresKeywords } from "./consts";
1615

1716
export function Explorer() {
1817
const { worldAddress } = useParams();
@@ -30,12 +29,10 @@ export function Explorer() {
3029
const tableName = constructTableName(table, worldAddress as Hex, chainId);
3130

3231
if (indexer.type === "sqlite") {
33-
setQuery(`SELECT * FROM "${tableName}"`);
32+
setQuery(`SELECT * FROM "${tableName}";`);
3433
} else {
35-
const columns = Object.keys(table.schema).map((column) =>
36-
postgresKeywords.includes(column.toLowerCase()) ? `"${column}"` : column,
37-
);
38-
setQuery(`SELECT ${columns.join(", ")} FROM ${tableName}`);
34+
const columns = Object.keys(table.schema).map((column) => `"${column}"`);
35+
setQuery(`SELECT ${columns.join(", ")} FROM ${tableName};`);
3936
}
4037
}
4138
}, [chainId, setQuery, selectedTableId, table, worldAddress, prevSelectedTableId, query, indexer.type]);

0 commit comments

Comments
 (0)