querybuilder 0.5.7 → 0.5.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/History.txt +7 -0
- data/Rakefile +49 -24
- data/lib/query_builder.rb +11 -3
- data/querybuilder.gemspec +73 -0
- data/test/mock/queries/bar.yml +8 -0
- data/test/mock/queries/foo.yml +11 -0
- data/test/{QueryBuilder → query_builder}/basic.yml +0 -0
- data/test/query_builder/custom.yml +62 -0
- data/test/{QueryBuilder → query_builder}/errors.yml +0 -0
- data/test/{QueryBuilder → query_builder}/filters.yml +0 -0
- data/test/{QueryBuilder → query_builder}/joins.yml +0 -0
- data/test/{QueryBuilder → query_builder}/mixed.yml +0 -0
- data/test/{test_QueryBuilder.rb → query_builder_test.rb} +6 -6
- metadata +24 -41
data/.gitignore
ADDED
data/History.txt
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
+
== 0.5.8 2010-02-15
|
2
|
+
|
3
|
+
* 1 major enhancement
|
4
|
+
* Const_get code was not included in gem
|
5
|
+
|
1
6
|
== 0.5.7 2010-02-08
|
7
|
+
|
2
8
|
* 1 minor enhancement
|
3
9
|
* Fixed class const_get to enable custom queries on classes in modules
|
4
10
|
|
5
11
|
== 0.5.6 2009-10-15
|
12
|
+
|
6
13
|
* 1 minor enhancement
|
7
14
|
* Fixed library name (was not loaded on case sensitive systems)
|
8
15
|
|
data/Rakefile
CHANGED
@@ -1,27 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
require 'pathname'
|
2
|
+
$LOAD_PATH.unshift((Pathname(__FILE__).dirname + 'lib').expand_path)
|
3
|
+
|
4
|
+
require 'querybuilder'
|
5
|
+
require 'rake'
|
6
|
+
require 'rake/testtask'
|
7
|
+
|
8
|
+
Rake::TestTask.new(:test) do |test|
|
9
|
+
test.libs << 'lib' << 'test'
|
10
|
+
test.pattern = 'test/**/**_test.rb'
|
11
|
+
test.verbose = true
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
require 'rcov/rcovtask'
|
16
|
+
Rcov::RcovTask.new do |test|
|
17
|
+
test.libs << 'test' << 'lib'
|
18
|
+
test.pattern = 'test/**/**_test.rb'
|
19
|
+
test.verbose = true
|
20
|
+
test.rcov_opts = ['-T', '--exclude-only', '"test\/,^\/"']
|
21
|
+
end
|
22
|
+
rescue LoadError
|
23
|
+
task :rcov do
|
24
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install rcov"
|
25
|
+
end
|
21
26
|
end
|
22
27
|
|
23
|
-
|
24
|
-
|
28
|
+
task :default => :test
|
29
|
+
|
30
|
+
# GEM management
|
31
|
+
begin
|
32
|
+
require 'jeweler'
|
33
|
+
Jeweler::Tasks.new do |gemspec|
|
34
|
+
gemspec.version = QueryBuilder::VERSION
|
35
|
+
gemspec.name = "querybuilder"
|
36
|
+
gemspec.summary = %Q{QueryBuilder is an interpreter for the "pseudo sql" language}
|
37
|
+
gemspec.description = %Q{QueryBuilder is an interpreter for the "pseudo sql" language. This language
|
38
|
+
can be used for two purposes:
|
39
|
+
|
40
|
+
1. protect your database from illegal SQL by securing queries
|
41
|
+
2. ease writing complex relational queries by abstracting table internals}
|
42
|
+
gemspec.email = "gaspard@teti.ch"
|
43
|
+
gemspec.homepage = "http://zenadmin.org/524"
|
44
|
+
gemspec.authors = ["Gaspard Bucher"]
|
45
|
+
|
46
|
+
gemspec.add_development_dependency('yamltest', '>= 0.5.0')
|
47
|
+
end
|
48
|
+
Jeweler::GemcutterTasks.new
|
49
|
+
rescue LoadError
|
50
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
51
|
+
end
|
25
52
|
|
26
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
27
|
-
# task :default => [:spec, :features]
|
data/lib/query_builder.rb
CHANGED
@@ -10,7 +10,7 @@ Syntax of a query is "RELATION [where ...|] [in ...|from SUB_QUERY|]".
|
|
10
10
|
=end
|
11
11
|
class QueryBuilder
|
12
12
|
attr_reader :tables, :where, :errors, :join_tables, :distinct, :final_parser, :page_size
|
13
|
-
VERSION = '0.5.
|
13
|
+
VERSION = '0.5.8'
|
14
14
|
|
15
15
|
@@main_table = {}
|
16
16
|
@@main_class = {}
|
@@ -70,7 +70,11 @@ class QueryBuilder
|
|
70
70
|
definitions = YAML::load(File.read(File.join(dir,file)))
|
71
71
|
custom_query_groups = [definitions.delete('groups') || definitions.delete('group') || custom_query_groups].flatten
|
72
72
|
definitions.each do |klass,v|
|
73
|
-
|
73
|
+
constant = nil
|
74
|
+
klass.split('::').each do |m|
|
75
|
+
constant = constant ? constant.const_get(m) : Module.const_get(m)
|
76
|
+
end
|
77
|
+
klass = constant
|
74
78
|
raise ArgumentError.new("invalid class for CustomQueries (#{klass})") unless klass.ancestors.include?(QueryBuilder)
|
75
79
|
@@custom_queries[klass] ||= {}
|
76
80
|
custom_query_groups.each do |custom_query_group|
|
@@ -205,7 +209,11 @@ class QueryBuilder
|
|
205
209
|
# DummyQuery.new("comments from nodes in project").main_class
|
206
210
|
# => Comment
|
207
211
|
def main_class
|
208
|
-
|
212
|
+
constant = nil
|
213
|
+
@@main_class[self.class].split('::').each do |m|
|
214
|
+
constant = constant ? constant.const_get(m) : Module.const_get(m)
|
215
|
+
end
|
216
|
+
constant
|
209
217
|
end
|
210
218
|
|
211
219
|
protected
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{querybuilder}
|
8
|
+
s.version = "0.5.8"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Gaspard Bucher"]
|
12
|
+
s.date = %q{2010-02-15}
|
13
|
+
s.description = %q{QueryBuilder is an interpreter for the "pseudo sql" language. This language
|
14
|
+
can be used for two purposes:
|
15
|
+
|
16
|
+
1. protect your database from illegal SQL by securing queries
|
17
|
+
2. ease writing complex relational queries by abstracting table internals}
|
18
|
+
s.email = %q{gaspard@teti.ch}
|
19
|
+
s.extra_rdoc_files = [
|
20
|
+
"README.rdoc"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".gitignore",
|
24
|
+
"History.txt",
|
25
|
+
"Manifest.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"lib/query_builder.rb",
|
29
|
+
"lib/querybuilder.rb",
|
30
|
+
"querybuilder.gemspec",
|
31
|
+
"script/console",
|
32
|
+
"script/destroy",
|
33
|
+
"script/generate",
|
34
|
+
"test/mock/custom_queries/test.yml",
|
35
|
+
"test/mock/dummy_query.rb",
|
36
|
+
"test/mock/queries/bar.yml",
|
37
|
+
"test/mock/queries/foo.yml",
|
38
|
+
"test/mock/user_query.rb",
|
39
|
+
"test/query_builder/basic.yml",
|
40
|
+
"test/query_builder/custom.yml",
|
41
|
+
"test/query_builder/errors.yml",
|
42
|
+
"test/query_builder/filters.yml",
|
43
|
+
"test/query_builder/joins.yml",
|
44
|
+
"test/query_builder/mixed.yml",
|
45
|
+
"test/query_builder_test.rb",
|
46
|
+
"test/test_helper.rb"
|
47
|
+
]
|
48
|
+
s.homepage = %q{http://zenadmin.org/524}
|
49
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
50
|
+
s.require_paths = ["lib"]
|
51
|
+
s.rubygems_version = %q{1.3.5}
|
52
|
+
s.summary = %q{QueryBuilder is an interpreter for the "pseudo sql" language}
|
53
|
+
s.test_files = [
|
54
|
+
"test/mock/dummy_query.rb",
|
55
|
+
"test/mock/user_query.rb",
|
56
|
+
"test/query_builder_test.rb",
|
57
|
+
"test/test_helper.rb"
|
58
|
+
]
|
59
|
+
|
60
|
+
if s.respond_to? :specification_version then
|
61
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
62
|
+
s.specification_version = 3
|
63
|
+
|
64
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
65
|
+
s.add_development_dependency(%q<yamltest>, [">= 0.5.0"])
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<yamltest>, [">= 0.5.0"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<yamltest>, [">= 0.5.0"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
File without changes
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# test2 context (queries = [abc,foo])
|
2
|
+
|
3
|
+
it_should_be_available:
|
4
|
+
context:
|
5
|
+
custom_query_group: test
|
6
|
+
src: "abc"
|
7
|
+
res: "\"SELECT a,34 AS number,c FROM test WHERE 3 AND 2 AND 1 ORDER BY a ASC\""
|
8
|
+
|
9
|
+
it_should_be_customizable:
|
10
|
+
context:
|
11
|
+
custom_query_group: test
|
12
|
+
src: "foo where name < 50"
|
13
|
+
res: "\"SELECT foo FROM foot WHERE objects.name < 50 ORDER BY f DESC\""
|
14
|
+
|
15
|
+
it_should_be_customizable_with_select_attributes:
|
16
|
+
context:
|
17
|
+
custom_query_group: test
|
18
|
+
src: "abc where number < 50"
|
19
|
+
res: "\"SELECT a,34 AS number,c FROM test WHERE (34) < 50 AND 3 AND 2 AND 1 ORDER BY a ASC\""
|
20
|
+
|
21
|
+
it_should_not_find_queries_not_in_group:
|
22
|
+
context:
|
23
|
+
custom_query_group: test
|
24
|
+
src: "bar"
|
25
|
+
res: "unknown relation 'bar'"
|
26
|
+
|
27
|
+
# test2 context (queries = [foo,bar])
|
28
|
+
it_should_not_find_queries_not_in_file_named_group:
|
29
|
+
context:
|
30
|
+
custom_query_group: test2
|
31
|
+
src: "abc"
|
32
|
+
res: "unknown relation 'abc'"
|
33
|
+
|
34
|
+
it_should_find_queries_in_group_list:
|
35
|
+
context:
|
36
|
+
custom_query_group: test2
|
37
|
+
src: "bar"
|
38
|
+
res: "\"SELECT bar FROM bart\""
|
39
|
+
|
40
|
+
it_should_use_the_first_table_as_main:
|
41
|
+
context:
|
42
|
+
custom_query_group: test
|
43
|
+
src: "two_table where x = '4' and name like 'B%'"
|
44
|
+
res: "[\"SELECT x,IF(table_one.y,table_one.y,table_two.z) AS y,table_two.name FROM table_one,table_two WHERE (x) = ? AND (table_two.name) LIKE ?\", \"4\", \"B%\"]"
|
45
|
+
|
46
|
+
it_should_use_main_table_as_main:
|
47
|
+
context:
|
48
|
+
custom_query_group: test
|
49
|
+
src: "two_table_main where name = '4'"
|
50
|
+
res: "[\"SELECT x FROM table_one,foo,table_two WHERE foo.name = ?\", \"4\"]"
|
51
|
+
|
52
|
+
it_should_limit_the_entries:
|
53
|
+
context:
|
54
|
+
custom_query_group: test
|
55
|
+
src: "abc limit 4"
|
56
|
+
res: "/LIMIT 4/"
|
57
|
+
|
58
|
+
it_should_paginate_the_entries:
|
59
|
+
context:
|
60
|
+
custom_query_group: test
|
61
|
+
src: "abc limit 4 paginate foo"
|
62
|
+
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]"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
|
4
|
-
class
|
4
|
+
class QueryBuilderTest < Test::Unit::TestCase
|
5
5
|
yamltest
|
6
|
-
|
6
|
+
|
7
7
|
def id; 123; end
|
8
8
|
def parent_id; 333; end
|
9
9
|
def project_id; 9999; end
|
10
10
|
def connection; self; end
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
|
13
13
|
def yt_parse(key, source, opts)
|
14
14
|
opts = Hash[*(opts.map{|k,v| [k.to_sym, v]}.flatten)]
|
15
15
|
query = DummyQuery.new(source, opts)
|
16
|
-
|
16
|
+
|
17
17
|
case key
|
18
18
|
when 'res'
|
19
19
|
(query.main_class != DummyQueryClass ? "#{query.main_class.to_s}: " : '') + if res = query.to_s
|
@@ -31,6 +31,6 @@ class DummyQueryBuilder < Test::Unit::TestCase
|
|
31
31
|
"parse not implemented for '#{key}' in query_builder_test.rb"
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
yt_make
|
36
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: querybuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gaspard Bucher
|
@@ -9,83 +9,64 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-15 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: yamltest
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.5.0
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: newgem
|
27
|
-
type: :development
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.3.0
|
34
|
-
version:
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: hoe
|
37
17
|
type: :development
|
38
18
|
version_requirement:
|
39
19
|
version_requirements: !ruby/object:Gem::Requirement
|
40
20
|
requirements:
|
41
21
|
- - ">="
|
42
22
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
23
|
+
version: 0.5.0
|
44
24
|
version:
|
45
25
|
description: |-
|
46
26
|
QueryBuilder is an interpreter for the "pseudo sql" language. This language
|
47
|
-
|
27
|
+
can be used for two purposes:
|
48
28
|
|
49
|
-
|
50
|
-
|
51
|
-
email:
|
52
|
-
- gaspard@teti.ch
|
29
|
+
1. protect your database from illegal SQL by securing queries
|
30
|
+
2. ease writing complex relational queries by abstracting table internals
|
31
|
+
email: gaspard@teti.ch
|
53
32
|
executables: []
|
54
33
|
|
55
34
|
extensions: []
|
56
35
|
|
57
36
|
extra_rdoc_files:
|
58
|
-
- History.txt
|
59
|
-
- Manifest.txt
|
60
37
|
- README.rdoc
|
61
38
|
files:
|
39
|
+
- .gitignore
|
62
40
|
- History.txt
|
63
41
|
- Manifest.txt
|
64
42
|
- README.rdoc
|
65
43
|
- Rakefile
|
66
44
|
- lib/query_builder.rb
|
67
45
|
- lib/querybuilder.rb
|
46
|
+
- querybuilder.gemspec
|
68
47
|
- script/console
|
69
48
|
- script/destroy
|
70
49
|
- script/generate
|
71
50
|
- test/mock/custom_queries/test.yml
|
72
51
|
- test/mock/dummy_query.rb
|
52
|
+
- test/mock/queries/bar.yml
|
53
|
+
- test/mock/queries/foo.yml
|
73
54
|
- test/mock/user_query.rb
|
74
|
-
- test/
|
75
|
-
- test/
|
76
|
-
- test/
|
77
|
-
- test/
|
78
|
-
- test/
|
55
|
+
- test/query_builder/basic.yml
|
56
|
+
- test/query_builder/custom.yml
|
57
|
+
- test/query_builder/errors.yml
|
58
|
+
- test/query_builder/filters.yml
|
59
|
+
- test/query_builder/joins.yml
|
60
|
+
- test/query_builder/mixed.yml
|
61
|
+
- test/query_builder_test.rb
|
79
62
|
- test/test_helper.rb
|
80
|
-
- test/test_QueryBuilder.rb
|
81
63
|
has_rdoc: true
|
82
|
-
homepage: http://
|
64
|
+
homepage: http://zenadmin.org/524
|
83
65
|
licenses: []
|
84
66
|
|
85
67
|
post_install_message:
|
86
68
|
rdoc_options:
|
87
|
-
- --
|
88
|
-
- README.rdoc
|
69
|
+
- --charset=UTF-8
|
89
70
|
require_paths:
|
90
71
|
- lib
|
91
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -102,11 +83,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
83
|
version:
|
103
84
|
requirements: []
|
104
85
|
|
105
|
-
rubyforge_project:
|
86
|
+
rubyforge_project:
|
106
87
|
rubygems_version: 1.3.5
|
107
88
|
signing_key:
|
108
89
|
specification_version: 3
|
109
90
|
summary: QueryBuilder is an interpreter for the "pseudo sql" language
|
110
91
|
test_files:
|
92
|
+
- test/mock/dummy_query.rb
|
93
|
+
- test/mock/user_query.rb
|
94
|
+
- test/query_builder_test.rb
|
111
95
|
- test/test_helper.rb
|
112
|
-
- test/test_QueryBuilder.rb
|