activerecord-simpledb-adapter 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.md CHANGED
@@ -23,6 +23,10 @@ config/database.yml:
23
23
  <<: *defaults
24
24
  domain_name: domain_name
25
25
 
26
+ for creating domain:
27
+
28
+ rake db:create
29
+
26
30
  model example:
27
31
  Person < ActiveRecord::Base
28
32
  columns_definition do |t|
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{activerecord-simpledb-adapter}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ilia Ablamonov", "Alex Gorkunov", "Cloud Castle Inc."]
12
- s.date = %q{2011-01-14}
12
+ s.date = %q{2011-01-17}
13
13
  s.email = %q{ilia@flamefork.ru}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -128,7 +128,7 @@ module ActiveRecord
128
128
  def mount_sql_and_params(klass, table_name, attribute, value) #:nodoc:
129
129
  column = klass.columns_hash[attribute.to_s]
130
130
 
131
- sql_attribute = "#{table_name}.#{klass.connection.quote_column_name(column.db_column_name)}"
131
+ sql_attribute = "#{klass.connection.quote_column_name(column.db_column_name)}"
132
132
  sql = "#{sql_attribute} = ?"
133
133
  if value.nil?
134
134
  [sql, [value]]
@@ -191,6 +191,8 @@ module ActiveRecord
191
191
  end
192
192
 
193
193
  def unquote_number value
194
+ return nil if value.nil?
195
+
194
196
  case sql_type
195
197
  when :integer then
196
198
  value.to_i - number_shift
@@ -275,6 +277,14 @@ module ActiveRecord
275
277
  super
276
278
  end
277
279
  end
280
+
281
+ def quote_column_name(column_name)
282
+ "`#{column_name}`"
283
+ end
284
+
285
+ def quote_table_name(table_name)
286
+ table_name
287
+ end
278
288
  #=======================================
279
289
 
280
290
  attr_reader :domain_name
@@ -398,7 +408,7 @@ module ActiveRecord
398
408
  end
399
409
 
400
410
  def get_collection_column_and_name sql
401
- if sql.match /(#{@@ccn.values.join("|")})\s*=\s*'(.*?)'/
411
+ if sql.match /`?(#{@@ccn.values.join("|")})`?\s*=\s*'(.*?)'/
402
412
  $2
403
413
  else
404
414
  raise PreparedStatementInvalid, "collection column '#{@@ccn.values.join(" or ")}' not found in the WHERE section in query"
@@ -40,7 +40,7 @@ module Arel
40
40
  o.cores.first.wheres << SqlLiteral.new("#{attr} IS NOT NULL")
41
41
  end
42
42
  collection = o.cores.first.froms.name
43
- o.cores.first.wheres << SqlLiteral.new("#{@connection.collection_column_name(collection)} = #{quote(collection)}")
43
+ o.cores.first.wheres << SqlLiteral.new("`#{@connection.collection_column_name(collection)}` = #{quote(collection)}")
44
44
  o.cores.first.froms = Table.new @connection.domain_name
45
45
  super
46
46
  end
@@ -63,12 +63,14 @@ module Arel
63
63
 
64
64
  def visit_Arel_Nodes_Assignment o
65
65
  right = o.right ? hash_value_quote(o.right, o.left.column) : nil
66
- {visit(o.left) => right}
66
+ left = o.left.column.name
67
+ {left => right}
67
68
  end
68
69
 
69
70
  def visit_Arel_Nodes_Equality o
70
71
  right = o.right ? hash_value_quote(o.right, o.left.column) : nil
71
- {visit(o.left) => right}.tap { |m|
72
+ left = o.left.column.name
73
+ {left => right}.tap { |m|
72
74
  m.override_to_s "#{visit o.left} = #{quote(o.right, o.left.column)}"
73
75
  }
74
76
  end
@@ -92,8 +94,7 @@ module Arel
92
94
  def visit_Arel_Nodes_SqlLiteral o
93
95
  # Strip table name from table.column -like literals
94
96
  result = o.to_s.gsub(/\w+\.([\w*]+)/, '\1')
95
-
96
- if result.match /(\w+)\s*=\s*'(.*?)'/
97
+ if result.match /`(\w+)`\s*=\s*'(.*?)'/
97
98
  # transform 'a = b' to {'a' => 'b'}
98
99
  {$1 => $2}.tap {|m| m.override_to_s result}
99
100
  else
@@ -138,4 +138,12 @@ describe "model with active_record_simple_db" do
138
138
  p = Person.where(:year => 2010).all
139
139
  p.should_not be_empty
140
140
  end
141
+
142
+ it "should be correct work with where statment with \"from\" column" do
143
+ p1 = Person.new
144
+ p1.from = 'test'
145
+ p1.save
146
+ p = Person.where(:from => 'test').all
147
+ p.should_not be_empty
148
+ end
141
149
  end
@@ -38,7 +38,7 @@ class Person < ActiveRecord::Base
38
38
  t.string :login
39
39
  t.integer :year, :limit => 4
40
40
  t.boolean :active
41
- t.string :state
41
+ t.string :from
42
42
  t.float :price
43
43
  t.integer :lock_version
44
44
 
@@ -51,7 +51,7 @@ class Person < ActiveRecord::Base
51
51
  :year => 2010,
52
52
  :active => true,
53
53
  :price => 10.04,
54
- :state => 'paid'
54
+ :from => 'paid'
55
55
  }
56
56
  end
57
57
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-simpledb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ilia Ablamonov
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-01-14 00:00:00 +03:00
20
+ date: 2011-01-17 00:00:00 +03:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency