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

add TOP clause support. #821

Merged
merged 25 commits into from
Feb 24, 2024
Merged

Conversation

igalklebanov
Copy link
Member

@igalklebanov igalklebanov commented Dec 29, 2023

Hey 👋

top clause is supported in dialects such as MS SQL Server (MSSQL) and Snowflake.

It works just like limit in other dialects, but has some interesting modifiers like percent.

It's the easiest way to limit rows in a select query, given that MSSQL doesn't have a limit clause. The alternative uses order by offset <n> rows fetch next <n> rows only which is less intuitive as it requires an extra step (order by ... offset).
It is also supported in insert ... select/update/delete/merge queries.

@igalklebanov igalklebanov added api Related to library's API enhancement New feature or request mssql Related to MS SQL Server (MSSQL) labels Dec 29, 2023
Copy link

vercel bot commented Dec 29, 2023

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 24, 2024 3:23pm

Copy link
Member

@koskimas koskimas left a comment

Choose a reason for hiding this comment

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

Check expression and modifier to prevent SQL injection. Then this is good to go. Great job!

@igalklebanov
Copy link
Member Author

Changes since last review:

  • added the parser to protect from SQL injection.
  • added support for top clause in merge queries.

"singleQuote": true,
"trailingComma": "all"
Copy link
Member Author

@igalklebanov igalklebanov Feb 21, 2024

Choose a reason for hiding this comment

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

prettier started making 982136491826341298632189 changes removing commas everywhere.

@igalklebanov igalklebanov merged commit d1c1322 into kysely-org:master Feb 24, 2024
5 checks passed
@igalklebanov igalklebanov deleted the feat-top branch February 24, 2024 15:32
thecodrr pushed a commit to thecodrr/kysely that referenced this pull request Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to library's API enhancement New feature or request mssql Related to MS SQL Server (MSSQL)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants