-
I couldn't find a straightforward way to add a diff --git a/src/marten/db/query/set.cr b/src/marten/db/query/set.cr
index 0de0fb56..9f730101 100644
--- a/src/marten/db/query/set.cr
+++ b/src/marten/db/query/set.cr
@@ -1152,6 +1152,20 @@ module Marten
qs
end
+ # Limits the number of records returned in the query result.
+ #
+ # ```
+ # query_set = Post.all
+ # query_set.limit(100)
+ # ```
+ #
+ # In the above example, at most 100 records will be returned.
+ def limit(number : Int)
+ qs = clone
+ qs.query.slice(0, number)
+ qs
+ end I feel like this is a fundamental feature that shouldn’t be missing, My goal is to generate SQL like this:
Would appreciate any feedback or suggestions! 🚀 |
Beta Was this translation helpful? Give feedback.
Answered by
ellmetha
Feb 2, 2025
Replies: 1 comment
-
Hey! 👋 Defining query set limits is something that is supported by the framework with the Post.all[...100] # Returns the first 100 Post records |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
miry
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! 👋
Defining query set limits is something that is supported by the framework with the
#[]
method. For example: