Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(torii-sql): sql playground for slot #2779

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/torii/server/static/sql-playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
ORDER BY m.name, p.cid;
`;
const response = await fetch(
"/sql?" + new URLSearchParams({ query: schemaQuery })
`${window.location.href}?` + new URLSearchParams({ query: schemaQuery })
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ohayo sensei! Consider improving URL construction.

The URL construction could be made more robust by handling trailing slashes and using proper URL joining.

Here's a suggested improvement:

- `${window.location.href}?` + new URLSearchParams({ query: schemaQuery })
+ `${new URL('sql', window.location.href)}?${new URLSearchParams({ query: schemaQuery })}`

This ensures:

  • Proper URL path joining
  • Handles trailing slashes correctly
  • Maintains the intended endpoint path
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`${window.location.href}?` + new URLSearchParams({ query: schemaQuery })
`${new URL('sql', window.location.href)}?${new URLSearchParams({ query: schemaQuery })}`

);
if (!response.ok) throw new Error("Failed to fetch schema");
const data = await response.json();
Expand Down Expand Up @@ -508,7 +508,7 @@
const startTime = performance.now();
try {
const response = await fetch(
"/sql?" + new URLSearchParams({ query })
`${window.location.href}?` + new URLSearchParams({ query })
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Similar URL construction improvement needed here, sensei!

For consistency and robustness, apply the same URL construction pattern here.

Here's the suggested improvement:

- `${window.location.href}?` + new URLSearchParams({ query })
+ `${new URL('sql', window.location.href)}?${new URLSearchParams({ query })}`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`${window.location.href}?` + new URLSearchParams({ query })
`${new URL('sql', window.location.href)}?${new URLSearchParams({ query })}`

);
if (!response.ok) throw new Error(await response.text());
const data = await response.json();
Expand Down
Loading