activerecord-crate-adapter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56df652b663e2d0dd2abcc83154b07b1575ee21b
4
- data.tar.gz: f9c8908ea5f6f296d05a16f4502ce12f430d8921
3
+ metadata.gz: b72a6d0d462cc8984a6925f8d44119ed4e9501b5
4
+ data.tar.gz: 8d00b8c20cc072b143f55caf53e133ae4878b1d0
5
5
  SHA512:
6
- metadata.gz: bf7d9a0a55a82065e81fbb3f9a1406e8524b81fef1f8803c0b0594eb4136b26a0af7fc20cf44439fca7390f49b42c4a6e7fde56dfc332c7a38baa9c9fb0689ff
7
- data.tar.gz: 6d0d522e9680e251477fada311f1a023ce349a507e43e13f668ee1210d2f7173997885e5da312c9eea957c5fddef827a88e35e24cc2c8f2cda25c87e441041ae
6
+ metadata.gz: 9e4f017f9f2ea9757378a9ae2d0aca1e91755b873ebcf2ebbf3938e174448033d48b24e8e7bd599cdfcd9e4b413fee5dc0514add07e4e2f2ada806eb5a662d93
7
+ data.tar.gz: 388ab7fc995ab6a112aa412b97c05ecb4a84da88555195ef21afaffc0becfcdeda055e1aa2f0b7576ec2fee06b2ae08a70b810d78b51445a6381f7d3dc1a8ef6
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - "2.1.1"
6
+ - "2.0.0"
7
+ - jruby-18mode # JRuby in 1.8 mode
8
+ - jruby-19mode # JRuby in 1.9 mode
9
+ - rbx
10
+ - rbx-2
11
+ # uncomment this line if your project needs to run something other than `rake`:
12
+ #script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,18 +1,14 @@
1
- # Activerecord::Crate::Adapter
1
+ [![Gem Version](https://badge.fury.io/rb/activerecord-crate-adapter.svg)](http://badge.fury.io/rb/activerecord-crate-adapter)
2
2
 
3
3
  The [Crate](http://www.crate.io) adapter for ActiveRecord.
4
4
 
5
- ## Work in progress
6
-
7
- I've just started coding the adapter and lots of functionality might still not work. Give it a try
8
- and help bei either contributing (fix it) or add an issue.
9
5
 
10
6
 
11
7
  ## Installation
12
8
 
13
9
  Add this line to your application's Gemfile:
14
10
 
15
- gem 'activerecord-crate-adapter', :git => "https://github.com/crate/activerecord-crate-adapter.git"
11
+ gem 'activerecord-crate-adapter'
16
12
 
17
13
  And then execute:
18
14
 
@@ -37,7 +33,7 @@ please add an issue so we can discuss.
37
33
 
38
34
  class Post < ActiveRecord::Base
39
35
 
40
- before_validation :set_id
36
+ before_validation :set_id, on: :create
41
37
 
42
38
  private
43
39
 
@@ -50,8 +46,7 @@ please add an issue so we can discuss.
50
46
  ## Special Data Types
51
47
 
52
48
  ### Array
53
- You can simply create Array columns by specifying t.array and passing array_type when you create a migration. You need at least the upcoming
54
- release 0.39 of Crate for this functionality.
49
+ You can simply create Array columns by specifying t.array and passing array_type when you create a migration.
55
50
 
56
51
  t.array :tags, array_type: :string
57
52
  t.array :votes, array_type: :integer
@@ -63,8 +58,7 @@ When you create an object just pass your Array directly
63
58
  post = Post.where("'fresh' = ANY (tags)")
64
59
 
65
60
  ### Object
66
- Crate allows you to define nested objects. You need at least the upcoming
67
- release 0.39 of Crate for this functionality. I tried to make it as simply as possible to use and reuse existing AR functionality,
61
+ Crate allows you to define nested objects. I tried to make it as simply as possible to use and reuse existing AR functionality,
68
62
  I therefore ask you to reuse the existing serialize functionality. AR#serialize allows you to define your own serialization
69
63
  mechanism and we simply reuse that for serializing an AR object. To get serialize working simply create a #dump and #load method
70
64
  on the class that creates a literal statement that is then used in the SQL. Read up more in this [commit}(https://github.com/crate/crate/commit/16a3d4b3f23996a327f91cdacef573f7ba946017).
data/history.txt CHANGED
@@ -1,5 +1,8 @@
1
1
  # coding: UTF-8
2
2
 
3
+ === 0.0.2
4
+ * Switched query execution to parameter substitution
5
+
3
6
  === 0.0.1
4
7
 
5
8
  Initial Release
@@ -12,19 +12,17 @@ module CrateObject
12
12
  end
13
13
 
14
14
  def dump(object)
15
- object ? object.to_literals : nil
15
+ object ? object.to_hash : nil
16
16
  end
17
17
  end
18
18
 
19
19
 
20
- def to_literals
21
- arr = []
20
+ def to_hash
21
+ h = {}
22
22
  instance_variables.each do |var|
23
- v = instance_variable_get(var)
24
- value = v.is_a?(Array) ? v : %Q{"#{v}"}
25
- arr << %Q{"#{var.to_s.gsub(/@/, '')}"=#{value}}
23
+ h.merge!({"#{var.to_s.gsub(/@/, '')}" => instance_variable_get(var)})
26
24
  end
27
- arr.join(', ')
25
+ h
28
26
  end
29
27
  end
30
28
 
@@ -26,13 +26,17 @@ module ActiveRecord
26
26
  params = []
27
27
  binds.each_with_index do |(column, value), index|
28
28
  ar_column = column.is_a?(ActiveRecord::ConnectionAdapters::Column)
29
- next if ar_column && column.sql_type == 'timestamp'
29
+ # only quote where clause values
30
+ unless ar_column # && column.sql_type == 'timestamp'
30
31
  v = value
31
32
  quoted_value = ar_column ? quote(v, column) : quote(v, nil)
32
33
  params << quoted_value
34
+ else
35
+ params << value
36
+ end
37
+
33
38
  end
34
- params.each { |p| sql.sub!(/(\?)/, p) }
35
- @connection.execute sql
39
+ @connection.execute sql, params
36
40
  end
37
41
 
38
42
  # Returns the statement identifier for the client side cache
@@ -11,7 +11,6 @@ require 'active_record/connection_adapters/statement_pool'
11
11
  require 'active_record/connection_adapters/column'
12
12
  require 'active_record/connection_adapters/crate/schema_statements'
13
13
  require 'active_record/connection_adapters/crate/database_statements'
14
- require 'active_record/connection_adapters/crate/quoting'
15
14
  require 'active_support/core_ext/kernel'
16
15
 
17
16
  begin
@@ -37,7 +36,6 @@ module ActiveRecord
37
36
 
38
37
  include Crate::SchemaStatements
39
38
  include DatabaseStatements
40
- include Crate::Quoting
41
39
 
42
40
  ADAPTER_NAME = 'Crate'.freeze
43
41
 
@@ -85,7 +83,7 @@ module ActiveRecord
85
83
 
86
84
  # Adds `:array` as a valid migration key
87
85
  def migration_keys
88
- super + [:array, :object_schema_behaviour, :object_schema_behaviour]
86
+ super + [:array, :object_schema_behaviour, :object_schema]
89
87
  end
90
88
 
91
89
 
@@ -1,3 +1,3 @@
1
1
  module ActiverecordCrateAdapter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -23,25 +23,39 @@ describe "Post#array" do
23
23
 
24
24
 
25
25
  describe "#array column type" do
26
- let(:array) {%w(hot fresh)}
27
- let(:votes) {[9,8,7]}
28
- let(:bool_arr) {[true, false, true]}
29
- let(:post) {Post.create!(title: 'Arrays are awesome', tags: array, votes: votes, bool_arr: bool_arr )}
30
-
31
- it 'should store and return an array' do
32
- p = Post.find(post.id)
33
- p.tags.should be_a Array
34
- p.votes.should be_a Array
35
- p.bool_arr.should be_a Array
36
- p.tags.should eq array
37
- p.votes.should eq votes
38
- p.bool_arr.should eq bool_arr
26
+ let(:array) { %w(hot fresh) }
27
+ let(:votes) { [9, 8, 7] }
28
+ let(:bool_arr) { [true, false, true] }
29
+ let(:post) { Post.create!(title: 'Arrays are awesome', tags: array, votes: votes, bool_arr: bool_arr) }
30
+
31
+ context 'create' do
32
+ it 'should store and return an array' do
33
+ p = Post.find(post.id)
34
+ p.tags.should be_a Array
35
+ p.votes.should be_a Array
36
+ p.bool_arr.should be_a Array
37
+ p.tags.should eq array
38
+ p.votes.should eq votes
39
+ p.bool_arr.should eq bool_arr
40
+ end
41
+
42
+ it 'should find the post by array value' do
43
+ post = Post.create!(title: 'Arrays are awesome', tags: array, votes: votes)
44
+ refresh_posts
45
+ Post.where("'fresh' = ANY (tags)").should include(post)
46
+ end
39
47
  end
40
48
 
41
- it 'should find the post by array value' do
42
- post = Post.create!(title: 'Arrays are awesome', tags: array, votes: votes)
43
- refresh_posts
44
- Post.where("'fresh' = ANY (tags)").should include(post)
49
+ context '#update' do
50
+ it 'should update and existing array value' do
51
+ post = Post.create!(title: 'Arrays are awesome', tags: array, votes: votes)
52
+ refresh_posts
53
+ new_tags = %w(ok)
54
+ post.update_attributes!(tags: new_tags)
55
+ refresh_posts
56
+ post.reload
57
+ post.tags.should eq new_tags
58
+ end
45
59
  end
46
60
 
47
61
  end
@@ -31,9 +31,16 @@ describe Post do
31
31
 
32
32
  context 'persistance' do
33
33
 
34
+ before do
35
+ @post = Post.create!(params)
36
+ end
37
+
38
+ after do
39
+ @post.destroy
40
+ end
41
+
34
42
  it 'should persist the record to the database' do
35
- post = Post.create!(params)
36
- post.persisted?.should be_true
43
+ @post.persisted?.should be_true
37
44
  refresh_posts
38
45
  Post.count.should eq 1
39
46
  end
@@ -58,7 +65,7 @@ describe Post do
58
65
  end
59
66
 
60
67
  after do
61
- #@post.destroy
68
+ @post.destroy
62
69
  end
63
70
 
64
71
  context 'find' do
@@ -66,6 +73,13 @@ describe Post do
66
73
  post = Post.where(id: @post.id).first
67
74
  post.id.should eq(@post.id)
68
75
  end
76
+
77
+ it 'should find the crated record by title' do
78
+ refresh_posts
79
+ Post.where(title: @post.title).count.should eq 1
80
+ post = Post.where(title: @post.title).first
81
+ post.id.should eq(@post.id)
82
+ end
69
83
  end
70
84
 
71
85
  context 'update' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-crate-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Klocker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,6 +117,7 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - ".gitignore"
120
+ - ".travis.yml"
120
121
  - Gemfile
121
122
  - LICENSE.txt
122
123
  - README.md
@@ -125,7 +126,6 @@ files:
125
126
  - history.txt
126
127
  - lib/active_record/attribute_methods/crate_object.rb
127
128
  - lib/active_record/connection_adapters/crate/database_statements.rb
128
- - lib/active_record/connection_adapters/crate/quoting.rb
129
129
  - lib/active_record/connection_adapters/crate/schema_statements.rb
130
130
  - lib/active_record/connection_adapters/crate_adapter.rb
131
131
  - lib/activerecord-crate-adapter.rb
@@ -178,4 +178,3 @@ test_files:
178
178
  - spec/models/post_spec.rb
179
179
  - spec/spec_helper.rb
180
180
  - spec/test_server.rb
181
- has_rdoc:
@@ -1,22 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module Crate
4
- module Quoting
5
- # Quotes the column value to help prevent
6
- # {SQL injection attacks}[http://en.wikipedia.org/wiki/SQL_injection].
7
- def quote(value, column = nil)
8
- # records are quoted as their primary key
9
- return value.quoted_id if value.respond_to?(:quoted_id)
10
-
11
- if value.is_a?(Array)
12
- "#{value}".gsub('"', "'")
13
- elsif column.sql_type == 'object'
14
- "{ #{value} }"
15
- else
16
- super(value, column)
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end