Skip to content
Browse files

Added support for limit and paginate in custom queries.

  • Loading branch information...
1 parent 6c6cd55 commit 6dd341d776ef99696582290f7f40f9ca5a910ad1 Gaspard Bucher committed Apr 8, 2009
Showing with 27 additions and 2 deletions.
  1. +5 −0 History.txt
  2. +9 −1 lib/QueryBuilder.rb
  3. +1 −1 querybuilder.gemspec
  4. +12 −0 test/QueryBuilder/custom.yml
View
5 History.txt
@@ -1,3 +1,8 @@
+== 0.5.3 2009-04-08
+
+* 1 minor enhancement:
+ * Added support for limit and paginate in custom queries
+
== 0.5.2 2009-04-03
* 1 minor enhancement:
View
10 lib/QueryBuilder.rb
@@ -10,7 +10,7 @@
=end
class QueryBuilder
attr_reader :tables, :where, :errors, :join_tables, :distinct, :final_parser, :page_size
- VERSION = '0.5.2'
+ VERSION = '0.5.3'
@@main_table = {}
@@main_class = {}
@@ -781,6 +781,14 @@ def parse_elements(elements)
clause, filters = elements[-1].split(/\s+where\s+/)
parse_filters(filters) if filters
+
+ @limit = parse_limit_clause(@offset_limit_order_group[:limit])
+ if @offset_limit_order_group[:paginate]
+ @offset = parse_paginate_clause(@offset_limit_order_group[:paginate])
+ else
+ @offset = parse_offset_clause(@offset_limit_order_group[:offset])
+ end
+
@order = parse_order_clause(@offset_limit_order_group[:order])
else
i, new_class = 0, nil
View
2 querybuilder.gemspec
@@ -3,7 +3,7 @@
Gem::Specification.new do |s|
s.name = %q{querybuilder}
- s.version = "0.5.2"
+ s.version = "0.5.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Gaspard Bucher"]
View
12 test/QueryBuilder/custom.yml
@@ -48,3 +48,15 @@ it_should_use_main_table_as_main:
custom_query_group: test
src: "two_table_main where name = '4'"
res: "[\"SELECT x FROM table_one,foo,table_two WHERE foo.name = ?\", \"4\"]"
+
+it_should_limit_the_entries:
+ context:
+ custom_query_group: test
+ src: "abc limit 4"
+ res: "/LIMIT 4/"
+
+it_should_paginate_the_entries:
+ context:
+ custom_query_group: test
+ src: "abc limit 4 paginate foo"
+ res: "[\"SELECT a,34 AS number,c FROM test WHERE 3 AND 2 AND 1 ORDER BY a ASC LIMIT 4 OFFSET ?\", ((foo.to_i > 0 ? foo.to_i : 1)-1)*4]"

0 comments on commit 6dd341d

Please sign in to comment.
Something went wrong with that request. Please try again.