tune_my_query 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +5 -5
- data/VERSION +1 -1
- data/init.rb +0 -1
- data/lib/tune_my_query/tune_my_query.rb +7 -5
- data/lib/tune_my_query.rb +3 -1
- data/pkg/tune_my_query-0.1.0.gem +0 -0
- data/spec/lib/tune_my_query_spec.rb +15 -4
- data/spec/models.rb +3 -0
- data/spec/schema.db +7 -0
- data/spec/spec_helper.rb +3 -3
- data/tune_my_query.gemspec +57 -0
- metadata +4 -2
data/README.markdown
CHANGED
@@ -3,7 +3,7 @@ tune_my_query
|
|
3
3
|
|
4
4
|
About
|
5
5
|
-----
|
6
|
-
**tune_my_query** is an extension of the gem **me_gusta** written by **[John Pignata]
|
6
|
+
**tune_my_query** is an extension of the gem **me_gusta** written by **[John Pignata](http://github.com/jpignata)**
|
7
7
|
|
8
8
|
It is a simple way to switch between standard SQL and extended SQL syntax depending on the adapter. For example: PostgreSql has an ILIKE extension which is not found in other databases like mysql. This gem(not released yet) ensures the query is adapted based on the current database.
|
9
9
|
|
@@ -20,16 +20,16 @@ It is simple to use. Just install it like:
|
|
20
20
|
|
21
21
|
sudo gem install tune_my_query
|
22
22
|
|
23
|
-
And do in the model class where you have used a database specific SQL, like this:
|
23
|
+
And do the following in the model class where you have used a database specific SQL, like this:
|
24
24
|
|
25
25
|
tune_my_query :like
|
26
26
|
|
27
|
-
Here like signifies the extension to usual SQL LIKE.
|
27
|
+
Here 'like' signifies the extension to usual SQL LIKE.
|
28
28
|
|
29
29
|
|
30
30
|
Does it only work with LIKE? What a futile effort
|
31
31
|
-------------------------------------------------
|
32
|
-
Yes, at the moment it only does that. But, you can fork the code and add your own commands in the commands directory
|
32
|
+
Yes, at the moment it only does that. But, you can fork the code and add your own commands in the lib/commands directory. Every new command you add should have a name ending with "Command". For example: AwesomeCommand. Add a singleton "execute" method to it and send me a patch, I will add it in. Please do add specs.
|
33
33
|
|
34
34
|
|
35
35
|
Specs
|
@@ -55,4 +55,4 @@ Authors
|
|
55
55
|
|
56
56
|
Roadmap
|
57
57
|
-------
|
58
|
-
* To make it work for any database extension. At the moment it would only for SQL extensions
|
58
|
+
* To make it work for any database extension. At the moment it would only work for PostgreSql specific SQL extensions.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/init.rb
CHANGED
@@ -36,11 +36,13 @@ module TuneMyQuery
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def standardise_sql(*conditions)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
if @command_type
|
40
|
+
conditions = conditions.dup
|
41
|
+
@adapter = connection && !connection.class.to_s.include?("PostgreSQLAdapter")
|
42
|
+
command = "#{@command_type.to_s.camelize}Command".constantize
|
43
|
+
if @adapter
|
44
|
+
conditions.each { |condition| command.execute(condition) }
|
45
|
+
end
|
44
46
|
end
|
45
47
|
super_merge_conditions(*conditions)
|
46
48
|
end
|
data/lib/tune_my_query.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
$: << File.join(File.dirname(__FILE__), "..", "lib")
|
2
2
|
|
3
3
|
require "tune_my_query/tune_my_query"
|
4
|
-
Dir.glob("#{File.dirname(__FILE__)}/tune_my_query/commands/*.*").each{|file| require file}
|
4
|
+
Dir.glob("#{File.dirname(__FILE__)}/tune_my_query/commands/*.*").each{|file| require file}
|
5
|
+
|
6
|
+
ActiveRecord::Base.send(:include, TuneMyQuery)
|
Binary file
|
@@ -21,9 +21,15 @@ describe "TuneMyQuery" do
|
|
21
21
|
context "for LIKE SQL command" do
|
22
22
|
it "should convert from postgresql specific to standard SQL" do
|
23
23
|
Auberdine.merge_conditions(["name = 'joe'"], ["address ilike 'main'"]).
|
24
|
-
should
|
25
|
-
end
|
26
|
-
|
24
|
+
should be_eql("(name = 'joe') AND (address like 'main')")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should ensure that other model objects work normally" do
|
28
|
+
Exodar.merge_conditions(["name = 'joe'"]).should be_eql("(name = 'joe')")
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
27
33
|
end
|
28
34
|
|
29
35
|
|
@@ -38,7 +44,12 @@ describe "TuneMyQuery" do
|
|
38
44
|
it "should not convert from postgresql specific to standard SQL" do
|
39
45
|
Auberdine.merge_conditions(["name = 'joe'"], ["address ilike 'main'"]).
|
40
46
|
should be_eql("(name = 'joe') AND (address ilike 'main')")
|
41
|
-
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should ensure that other model objects work normally" do
|
50
|
+
Exodar.merge_conditions(["name = 'joe'"]).should be_eql("(name = 'joe')")
|
51
|
+
end
|
52
|
+
|
42
53
|
end
|
43
54
|
|
44
55
|
end
|
data/spec/models.rb
CHANGED
data/spec/schema.db
CHANGED
@@ -5,4 +5,11 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
5
5
|
t.datetime "created_at"
|
6
6
|
t.datetime "updated_at"
|
7
7
|
end
|
8
|
+
|
9
|
+
create_table "exodar", :force => true do |t|
|
10
|
+
t.string "name"
|
11
|
+
t.string "description"
|
12
|
+
t.datetime "created_at"
|
13
|
+
t.datetime "updated_at"
|
14
|
+
end
|
8
15
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
%w(activerecord active_support yaml spec).each{|path| require path }
|
2
|
+
|
1
3
|
require File.join(File.dirname(__FILE__), "..", "lib", "tune_my_query")
|
2
4
|
|
3
|
-
%w(
|
5
|
+
%w(models).each{|path| require File.join(File.dirname(__FILE__), path) }
|
4
6
|
|
5
|
-
%w(../init models).each{|path| require File.join(File.dirname(__FILE__), path) }
|
6
|
-
|
7
7
|
def connect(adapter)
|
8
8
|
fix_quote_ident_postgres_error if adapter == "postgres"
|
9
9
|
conf = YAML::load(File.open(File.dirname(__FILE__) + '/database.yml'))
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{tune_my_query}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Anuj Dutta"]
|
12
|
+
s.date = %q{2009-12-16}
|
13
|
+
s.description = %q{Switches between standard SQL and extended SQL syntax depending on the adapter.}
|
14
|
+
s.email = %q{anuj@andhapp.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"HISTORY",
|
21
|
+
"LICENSE",
|
22
|
+
"README.markdown",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"init.rb",
|
26
|
+
"lib/tune_my_query.rb",
|
27
|
+
"lib/tune_my_query/commands/LikeCommand.rb",
|
28
|
+
"lib/tune_my_query/tune_my_query.rb",
|
29
|
+
"pkg/tune_my_query-0.1.0.gem",
|
30
|
+
"spec/database.yml",
|
31
|
+
"spec/lib/tune_my_query_spec.rb",
|
32
|
+
"spec/models.rb",
|
33
|
+
"spec/schema.db",
|
34
|
+
"spec/spec_helper.rb",
|
35
|
+
"tune_my_query.gemspec"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/andhapp/tune_my_query}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.5}
|
41
|
+
s.summary = %q{Standardises SQL syntax across databases.}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/lib/tune_my_query_spec.rb",
|
44
|
+
"spec/models.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
+
else
|
54
|
+
end
|
55
|
+
else
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tune_my_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anuj Dutta
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-16 00:00:00 +05:30
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -32,11 +32,13 @@ files:
|
|
32
32
|
- lib/tune_my_query.rb
|
33
33
|
- lib/tune_my_query/commands/LikeCommand.rb
|
34
34
|
- lib/tune_my_query/tune_my_query.rb
|
35
|
+
- pkg/tune_my_query-0.1.0.gem
|
35
36
|
- spec/database.yml
|
36
37
|
- spec/lib/tune_my_query_spec.rb
|
37
38
|
- spec/models.rb
|
38
39
|
- spec/schema.db
|
39
40
|
- spec/spec_helper.rb
|
41
|
+
- tune_my_query.gemspec
|
40
42
|
has_rdoc: true
|
41
43
|
homepage: http://github.com/andhapp/tune_my_query
|
42
44
|
licenses: []
|