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

improvement: better sql completions #3930

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Light2Dark
Copy link
Collaborator

@Light2Dark Light2Dark commented Feb 27, 2025

📝 Summary

Follow up from #3898 , add the shortest and correct completions to AI & sql completions panel.
Adds default schema & db introspection + update API.
image

🔍 Description of Changes

  • For default schema & db, we just surface the table name as the completion. Else, use schema_name.table_name, for diff databases, use db_name.schema_name.table_name

Maybe:

  • Can improve the view for sql & ai completions, to maybe show which schema it's coming from. And maybe icons improvement.

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • I have added tests for the changes made.
  • I have run the code and verified that it works as expected.

📜 Reviewers

@akshayka OR @mscolnick

Copy link

vercel bot commented Feb 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marimo-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 27, 2025 4:17pm
marimo-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 27, 2025 4:17pm


export const ItemSubtext: React.FC<{ content: string }> = ({ content }) => {
return (
<span className="text-xs text-black bg-gray-200 rounded px-1">
Copy link
Contributor

Choose a reason for hiding this comment

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

bg-gray-200 won't support dark mode, and i think it could be slightly lighter

maybe bg-[var(--slate-8] text-[var(--slate-9]?

@@ -361,6 +378,8 @@ const SchemaItem: React.FC<{
<span className={cn(isSelected && isExpanded && "font-semibold")}>
{schema.name}
</span>
{/* Do we want this? They could change the default by executing USE schema.. */}
{isDefaultSchema && <ItemSubtext content="default" />}
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can remove for now? we can look if other SQL apps do this:
e.g. jetbrains or dbbeaver, if you can drum up screenshots (but don't need to spend too much time)

tables[table.name] = columns;

if (isDefaultDb) {
const schemaMap = (mapping[schema.name] ?? {}) as Record<
Copy link
Contributor

Choose a reason for hiding this comment

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

you can put the typecheck on the LHS const schemaMap: Record<string, string[]>;. this might be safer than casting

database_name: Optional[str] = None
dialect_queries = {
"postgresql": "SELECT current_database()",
"mssql": "SELECT DB_NAME()",
Copy link
Contributor

Choose a reason for hiding this comment

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

i guess sql alchemy or the inspect class doesn't have native support for this?

Copy link
Collaborator Author

@Light2Dark Light2Dark Feb 27, 2025

Choose a reason for hiding this comment

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

yeah, that's true, the inspector is schema oriented. Supporting multi-database inspection is a little bit tricky, even though you can execute queries from another db

cacheConfig = {
dialect: guessDialect(connection),
schema: combinedSchema,
schema: mapping,
defaultSchema: connection.default_schema ?? undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

can you verify that the table from the default schema does get bubbled up? im not sure if this include the db.schema, but that might be required

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeap it does! Will attach a screenshot/vid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants