Skip to content

Commit

Permalink
fix(explorer): format default sql query (#3363)
Browse files Browse the repository at this point in the history
  • Loading branch information
karooolis authored Nov 6, 2024
1 parent 3168f1f commit 0facee0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 377 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-spies-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/explorer": patch
---

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.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { indexerForChainId } from "../../../../utils/indexerForChainId";
import { SQLEditor } from "./SQLEditor";
import { TableSelector } from "./TableSelector";
import { TablesViewer } from "./TablesViewer";
import { postgresKeywords } from "./consts";

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

if (indexer.type === "sqlite") {
setQuery(`SELECT * FROM "${tableName}"`);
setQuery(`SELECT * FROM "${tableName}";`);
} else {
const columns = Object.keys(table.schema).map((column) =>
postgresKeywords.includes(column.toLowerCase()) ? `"${column}"` : column,
);
setQuery(`SELECT ${columns.join(", ")} FROM ${tableName}`);
const columns = Object.keys(table.schema).map((column) => `"${column}"`);
setQuery(`SELECT ${columns.join(", ")} FROM ${tableName};`);
}
}
}, [chainId, setQuery, selectedTableId, table, worldAddress, prevSelectedTableId, query, indexer.type]);
Expand Down
Loading

0 comments on commit 0facee0

Please sign in to comment.