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

refactor: improve sqlite-introspector metadata query #1349

Conversation

tgriesser
Copy link
Contributor

Minor change to follow up on #1344

The change to using a union all means that although there's now only one query, the query grows to be as long as the number of tables in the DB, which feels a little off.

Decided to see if there was a way to handle this that was a little cleaner and came up with:

with "table_list" as (
  select "name", "sql", "type" from "sqlite_master"
  where "type" in ('table', 'view')
  and "name" not like 'sqlite_%' order by "name"
)
select
  "tl"."name" as "table",
  "p"."cid",
  "p"."name",
  "p"."type",
  "p"."notnull",
  "p"."dflt_value",
  "p"."pk"
from
  "table_list" as "tl",
  pragma_table_info(tl.name) as "p"
order by "tl.name", "p.cid"

Which feels a little nicer than an really large union query

Copy link

vercel bot commented Feb 8, 2025

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

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 8, 2025 9:54pm

Copy link

pkg-pr-new bot commented Feb 8, 2025

Open in Stackblitzkysely_koa_example

npm i https://pkg.pr.new/kysely-org/kysely@1349

commit: f5f005b

@igalklebanov igalklebanov added sqlite Related to sqlite built-in dialect Related to a built-in dialect labels Feb 8, 2025
Copy link
Member

@igalklebanov igalklebanov left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

Thanks! 🙏

@igalklebanov igalklebanov merged commit 0d87f94 into kysely-org:master Feb 8, 2025
24 checks passed
@tgriesser tgriesser deleted the tgriesser/refactor/sqlite-introspection branch February 8, 2025 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
built-in dialect Related to a built-in dialect sqlite Related to sqlite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants