querybuilder 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +7 -2
- data/README.rdoc +2 -0
- data/lib/query_builder/info.rb +1 -1
- data/lib/querybuilder_ext.c +2139 -1502
- data/lib/querybuilder_rb.rb +1981 -1378
- data/lib/querybuilder_syntax.rl +5 -3
- data/querybuilder.gemspec +3 -13
- data/test/mock/dummy_processor.rb +4 -1
- data/test/querybuilder/basic.yml +11 -1
- metadata +7 -14
data/lib/querybuilder_syntax.rl
CHANGED
@@ -11,18 +11,20 @@
|
|
11
11
|
dquote = ([^"\\] | '\n') $str_a | ('\\' (any | '\n') $str_a);
|
12
12
|
squote = ([^'\\] | '\n') $str_a | ('\\' (any | '\n') $str_a);
|
13
13
|
string = ws* ("'" squote* "'" >string | '"' dquote* '"' >dstring);
|
14
|
-
field = var %field ('.' %function var %method)*;
|
15
14
|
rcontent = ('"' dquote* '"') $str_a | ([^\}"\\] | '\n') $str_a | ('\\' (any | '\n') $str_a) ;
|
16
15
|
rubyless = ws* "#{" rcontent+ "}" >rubyless ('.' %function var %method)*;
|
17
16
|
real = ws* ('-'? ('0'..'9' digit* '.' digit+) ) $str_a %real;
|
18
17
|
integer = ws* ('-'? digit+ ) $str_a %integer;
|
19
18
|
number = (real | integer);
|
19
|
+
literal = (string | number | rubyless);
|
20
|
+
|
21
|
+
field = var %field ('.' %function var %method ('(' (var %field | literal) (',' (var % field | literal))* ')')*)*;
|
20
22
|
op = ws* ('+' | '-' | '<' | '<=' | '=' | '>=' | '>') $str_a;
|
21
23
|
text_op = ws+ (('or' | 'and' | 'lt' | 'le' | 'eq' | 'ne' | 'ge' | 'gt' | 'match') $str_a | ('not' $str_a %operator ws+)? 'like' $str_a);
|
22
24
|
operator = (op %operator | text_op %operator ws+ );
|
23
25
|
interval = ws+ ('second'|'minute'|'hour'|'day'|'week'|'month'|'year') $str_a %interval 's'?;
|
24
|
-
value = ((field |
|
25
|
-
in_value =
|
26
|
+
value = ((field | literal) interval? | ws* '(' >goto_expr_p ws* ')');
|
27
|
+
in_value = literal (ws* ',' literal)*;
|
26
28
|
in_expr = ws+ ('not' $str_a %operator ws+)? 'in' ws* '(' %in_op in_value ws* ')'; # wait until '(' to execute 'operator' to avoid confusion with scope
|
27
29
|
is_null = ws+ 'is' %is ws+ (('not' ws+)* ('null' | 'NULL')) $str_a %raw;
|
28
30
|
expr = value (operator value | in_expr | is_null)*;
|
data/querybuilder.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{querybuilder}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gaspard Bucher"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-11-01}
|
13
13
|
s.description = %q{QueryBuilder is an interpreter for the "pseudo sql" language. This language
|
14
14
|
can be used for two purposes:
|
15
15
|
|
@@ -68,18 +68,8 @@ Gem::Specification.new do |s|
|
|
68
68
|
]
|
69
69
|
s.homepage = %q{http://zenadmin.org/524}
|
70
70
|
s.require_paths = ["lib"]
|
71
|
-
s.rubygems_version = %q{1.6.
|
71
|
+
s.rubygems_version = %q{1.6.2}
|
72
72
|
s.summary = %q{QueryBuilder is an interpreter for the "pseudo sql" language.}
|
73
|
-
s.test_files = [
|
74
|
-
"test/database.rb",
|
75
|
-
"test/dummy_test.rb",
|
76
|
-
"test/mock/dummy.rb",
|
77
|
-
"test/mock/dummy_processor.rb",
|
78
|
-
"test/mock/user_processor.rb",
|
79
|
-
"test/query_test.rb",
|
80
|
-
"test/querybuilder_test.rb",
|
81
|
-
"test/test_helper.rb"
|
82
|
-
]
|
83
73
|
|
84
74
|
if s.respond_to? :specification_version then
|
85
75
|
s.specification_version = 3
|
@@ -77,7 +77,7 @@ class DummyProcessor < QueryBuilder::Processor
|
|
77
77
|
def process_match(left, right)
|
78
78
|
end
|
79
79
|
|
80
|
-
def process_function(arg, method)
|
80
|
+
def process_function(arg, method, *args)
|
81
81
|
method, arg = process(method), process(arg)
|
82
82
|
|
83
83
|
case method
|
@@ -87,6 +87,9 @@ class DummyProcessor < QueryBuilder::Processor
|
|
87
87
|
"COUNT(#{arg})"
|
88
88
|
when 'sum'
|
89
89
|
"SUM(#{arg})"
|
90
|
+
when 'coalesce'
|
91
|
+
args = [arg] + args.map{|a| process(a)}
|
92
|
+
"COALESCE(#{args.join(',')})"
|
90
93
|
else
|
91
94
|
super
|
92
95
|
end
|
data/test/querybuilder/basic.yml
CHANGED
@@ -89,4 +89,14 @@ after_process_callback:
|
|
89
89
|
context:
|
90
90
|
after_filter: '(1 = 1)'
|
91
91
|
src: "objects where name like 'a%' or name like 'b%' in site"
|
92
|
-
res: "%Q{SELECT objects.* FROM objects WHERE (1 = 1) AND (objects.name LIKE 'a%' OR objects.name LIKE 'b%') GROUP BY id}"
|
92
|
+
res: "%Q{SELECT objects.* FROM objects WHERE (1 = 1) AND (objects.name LIKE 'a%' OR objects.name LIKE 'b%') GROUP BY id}"
|
93
|
+
|
94
|
+
function:
|
95
|
+
src: "objects where event_at.year = 2005"
|
96
|
+
sxp: '[:query, [:filter, [:relation, "objects"], [:"=", [:function, [:field, "event_at"], [:method, "year"]], [:integer, "2005"]]]]'
|
97
|
+
res: "[%Q{SELECT objects.* FROM objects WHERE strftime('%Y',objects.event_at) = 2005 AND objects.parent_id = ?}, id]"
|
98
|
+
|
99
|
+
function_with_multiple_args:
|
100
|
+
src: "objects where name.coalesce(id,'foo') = 'foo'"
|
101
|
+
sxp: '[:query, [:filter, [:relation, "objects"], [:"=", [:function, [:field, "name"], [:method, "coalesce"], [:field, "id"], [:string, "foo"]], [:string, "foo"]]]]'
|
102
|
+
res: "[%Q{SELECT objects.* FROM objects WHERE COALESCE(objects.name,objects.id,'foo') = 'foo' AND objects.parent_id = ?}, id]"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: querybuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gaspard Bucher
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-01 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -152,16 +152,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
requirements: []
|
153
153
|
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 1.6.
|
155
|
+
rubygems_version: 1.6.2
|
156
156
|
signing_key:
|
157
157
|
specification_version: 3
|
158
158
|
summary: QueryBuilder is an interpreter for the "pseudo sql" language.
|
159
|
-
test_files:
|
160
|
-
|
161
|
-
- test/dummy_test.rb
|
162
|
-
- test/mock/dummy.rb
|
163
|
-
- test/mock/dummy_processor.rb
|
164
|
-
- test/mock/user_processor.rb
|
165
|
-
- test/query_test.rb
|
166
|
-
- test/querybuilder_test.rb
|
167
|
-
- test/test_helper.rb
|
159
|
+
test_files: []
|
160
|
+
|