ar_jdbc_pg_array 0.1.0-java → 0.1.1-java

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/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - jruby-18mode
4
+ - jruby-19mode
5
+ matrix:
6
+ allow_failures:
7
+ - rvm: jruby-18mode
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Sokolov Yura aka funny_falcon
1
+ Copyright (c) 2010-2013 Sokolov Yura aka funny_falcon
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,48 +1,59 @@
1
- PostgresArrays
2
- ==============
1
+ ## ActiveRecord JDBC PostgreSQL Arrays [![Build Status](https://travis-ci.org/dimko/activerecord-jdbc-postgresql-arrays.png?branch=master)](https://travis-ci.org/dimko/activerecord-jdbc-postgresql-arrays)
3
2
 
4
3
  This library adds ability to use PostgreSQL array types with ActiveRecord.
5
4
 
6
- > User.find(:all, :conditions=>['arr @> ?', [1,2,3].pg])
7
- SELECT * FROM "users" WHERE ('arr' @> E'{"1", "2", "3"}')
8
- > User.find(:all, :conditions=>['arr @> ?', [1,2,3].pg(:integer)])
9
- SELECT * FROM "users" WHERE (arr @> '{1,2,3}')
10
- > User.find(:all, :conditions=>['arr @> ?', [1,2,3].pg(:float)])
11
- SELECT * FROM "users" WHERE (arr @> '{1.0,2.0,3.0}')
12
- > u = User.find(1)
13
- SELECT * FROM "users" WHERE ("users"."id" = 1)
14
- => #<User id: 1, ..., arr: [1,2]>
15
- > u.arr = [3,4]
16
- > u.save
17
- UPDATE "users" SET "db_ar" = '{3.0,4.0}' WHERE "id" = 19
18
- > User.find(:all, :conditions=>{:arr=>[3,4].pg})
19
- SELECT * FROM "users" WHERE ("users"."arr" = E'{"3", "4"}')
20
- > User.find(:all, :conditions=>{:arr=>[3,4].search_any(:float)})
21
- SELECT * FROM "users" WHERE ("users"."arr" && '{3.0,4.0}')
22
- > User.find(:all, :conditions=>{:arr=>[3,4].search_all(:integer)})
23
- SELECT * FROM "users" WHERE ("users"."arr" @> '{3,4}')
24
- > User.find(:all, :conditions=>{:arr=>[3,4].search_subarray(:safe)})
25
- SELECT * FROM "users" WHERE ("users"."arr" <@ '{3,4}')
26
-
27
- class U < ActiveRecord::Migration
28
- def self.up
29
- create_table :users do |t|
30
- t.integer_array :int_ar
31
- end
32
- add_column :users, :fl_ar, :float_array
33
- end
34
- end
35
-
36
- Installation
37
- ============
38
-
39
- gem install ar_jdbc_pg_array
40
-
41
- Changelog
42
- =========
43
-
44
- 0.1.0
45
-
46
- Initial jdbc support
47
-
48
- Copyright (c) 2010 Sokolov Yura aka funny_falcon, released under the MIT license
5
+ ### Queries
6
+
7
+ ```ruby
8
+ User.find(:all, :conditions => ['arr @> ?', [1,2,3].pg])
9
+ # SELECT * FROM "users" WHERE ('arr' @> E'{"1", "2", "3"}')
10
+ User.find(:all, :conditions => ['arr @> ?', [1,2,3].pg(:integer)])
11
+ # SELECT * FROM "users" WHERE (arr @> '{1,2,3}')
12
+ User.find(:all, :conditions => ['arr @> ?', [1,2,3].pg(:float)])
13
+ # SELECT * FROM "users" WHERE (arr @> '{1.0,2.0,3.0}')
14
+ u = User.find(1)
15
+ # SELECT * FROM "users" WHERE ("users"."id" = 1)
16
+ #=> #<User id: 1, ..., arr: [1,2]>
17
+ u.arr = [3,4]
18
+ u.save
19
+ # UPDATE "users" SET "db_ar" = '{3.0,4.0}' WHERE "id" = 19
20
+ User.find(:all, :conditions => { :arr => [3,4].pg })
21
+ # SELECT * FROM "users" WHERE ("users"."arr" = E'{"3", "4"}')
22
+ User.find(:all, :conditions => { :arr => [3,4].search_any(:float) })
23
+ # SELECT * FROM "users" WHERE ("users"."arr" && '{3.0,4.0}')
24
+ User.find(:all, :conditions => { :arr => [3,4].search_all(:integer) })
25
+ # SELECT * FROM "users" WHERE ("users"."arr" @> '{3,4}')
26
+ User.find(:all, :conditions => { :arr => [3,4].search_subarray(:safe) })
27
+ # SELECT * FROM "users" WHERE ("users"."arr" <@ '{3,4}')
28
+ ```
29
+
30
+ ### Migrations
31
+
32
+ ```ruby
33
+ class CreateUsers < ActiveRecord::Migration
34
+ def self.up
35
+ create_table :users do |t|
36
+ t.integer_array :int_ar
37
+ end
38
+ add_column :users, :fl_ar, :float_array
39
+ end
40
+ end
41
+ ```
42
+
43
+ ### Installation
44
+
45
+ Add this line to your application's Gemfile:
46
+
47
+ gem 'ar_jdbc_pg_array'
48
+
49
+ And then execute:
50
+
51
+ $ bundle
52
+
53
+ Or install it yourself as:
54
+
55
+ $ gem install ar_jdbc_pg_array
56
+
57
+ ### Credits
58
+
59
+ Copyright (c) 2010-2013 Sokolov Yura aka funny_falcon, released under the MIT license.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = 'ar_jdbc_pg_array'
4
- gem.version = '0.1.0'
4
+ gem.version = '0.1.1'
5
5
  gem.platform = 'java'
6
6
 
7
7
  gem.authors = ['Sokolov Yura', 'Dimko']
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.add_dependency 'activerecord', '~> 3.1'
18
18
  gem.add_dependency 'activerecord-jdbcpostgresql-adapter', '~> 1.2.9'
19
+ gem.add_dependency 'json'
19
20
 
20
21
  gem.add_development_dependency 'rake'
21
22
  gem.add_development_dependency 'cancan'
@@ -8,7 +8,7 @@ describe "PgArray" do
8
8
  end
9
9
  @acheck = Struct.new(:a)
10
10
  end
11
-
11
+
12
12
  before :each do
13
13
  @ability = @ability_class.new
14
14
  end
@@ -19,7 +19,7 @@ describe "PgArray" do
19
19
  [].search_all.should be_an_instance_of(PGArrays::PgAll)
20
20
  [].search_subarray.should be_an_instance_of(PGArrays::PgIncludes)
21
21
  end
22
-
22
+
23
23
  it "should provide search_any for cancan" do
24
24
  ab.can :boom, @acheck, :a => [1, 2].search_any
25
25
  ab.should be_able_to(:boom, the([1]))
@@ -30,7 +30,7 @@ describe "PgArray" do
30
30
  ab.should_not be_able_to(:boom, the([3]))
31
31
  ab.should_not be_able_to(:boom, the([]))
32
32
  end
33
-
33
+
34
34
  it "should provide search_all for cancan" do
35
35
  ab.can :boom, @acheck, :a => [1, 2].search_all
36
36
  ab.should_not be_able_to(:boom, the([1]))
@@ -41,7 +41,7 @@ describe "PgArray" do
41
41
  ab.should_not be_able_to(:boom, the([3]))
42
42
  ab.should_not be_able_to(:boom, the([]))
43
43
  end
44
-
44
+
45
45
  it "should provide search_subarray for cancan" do
46
46
  ab.can :boom, @acheck, :a => [1, 2].search_subarray
47
47
  ab.should be_able_to(:boom, the([1]))
@@ -52,22 +52,22 @@ describe "PgArray" do
52
52
  ab.should_not be_able_to(:boom, the([3]))
53
53
  ab.should be_able_to(:boom, the([]))
54
54
  end
55
-
55
+
56
56
  def the(ar)
57
57
  @acheck.new(ar)
58
58
  end
59
-
59
+
60
60
  def ab
61
61
  @ability
62
62
  end
63
63
  end
64
-
64
+
65
65
  context "AR" do
66
66
  it "should adequatly insert fixtures" do
67
67
  bulk = Bulk.find(1)
68
68
  bulk.ints.should == [ 1 ]
69
69
  bulk.strings.should == %w{one}
70
- map_times(bulk.times).should ==
70
+ map_times(bulk.times).should ==
71
71
  map_times(parse_times(%w{2011-03-01 2011-05-05}))
72
72
  bulk.floats.should == [1.0, 2.3]
73
73
  bulk.decimals.should == [1.0, 2.3]
@@ -80,7 +80,7 @@ describe "PgArray" do
80
80
  bulk.floats.should == [1.0, 1.2]
81
81
  bulk.decimals.should == [1.0, 1.2]
82
82
  bulk.texts.should == [nil, 'Text', 'NULL', 'Text with nil', 'Text with , nil, !"\\', 'nil']
83
- map_times(bulk.times).should ==
83
+ map_times(bulk.times).should ==
84
84
  map_times(parse_times(%w{2010-01-01 2010-02-01}))
85
85
  bulk.empty_def.should == []
86
86
  end
@@ -106,7 +106,7 @@ describe "PgArray" do
106
106
  bulk = Bulk.new
107
107
  bulk.strings.should == %w{as so}
108
108
  end
109
-
109
+
110
110
  it "should save changes" do
111
111
  bulk = Bulk.find(3)
112
112
  for field in %w{ints strings floats decimals times}
@@ -120,7 +120,7 @@ describe "PgArray" do
120
120
  bulk.decimals.should == [2.5, 2]
121
121
  map_times(bulk.times).should == map_times(parse_times(%w{2010-04-01 2010-03-01}))
122
122
  end
123
-
123
+
124
124
  it "should save right text" do
125
125
  bulk = Bulk.find(5)
126
126
  bulk.texts = ['Text with , nil, !\x01\\\'"',"Text with , nil, !\x01\n\\\'\""]
@@ -168,21 +168,21 @@ describe "PgArray" do
168
168
  it "should allow to use sql" do
169
169
  bulks_where(['ints && ?', [1,2].pg]).should == bulks_where(:id=>[1,2,3])
170
170
  end
171
-
171
+
172
172
  it "should allow to use finders" do
173
173
  bulks_where(:ints => [2].search_any).should == bulks_where(:id=>[2,3])
174
174
  bulks_where(:ints => [2,3].search_any).should == bulks_where(:id=>[2,3])
175
175
  bulks_where(:ints => [1,2].search_any).should == bulks_where(:id=>[1,2,3])
176
-
176
+
177
177
  bulks_where(:ints => [2].search_all).should == bulks_where(:id=>[2,3])
178
178
  bulks_where(:ints => [2,3].search_all).should == bulks_where(:id=>[3])
179
179
  bulks_where(:ints => [1,2].search_all).should == []
180
-
180
+
181
181
  bulks_where(:ints => [2].search_subarray).should == bulks_where(:id=>[2,4])
182
182
  bulks_where(:ints => [2,3].search_subarray).should == bulks_where(:id=>[2,3,4])
183
183
  bulks_where(:ints => [1,2].search_subarray).should == bulks_where(:id=>[1,2,4])
184
184
  end
185
-
185
+
186
186
  it "should be cached in @attributes_cache" do
187
187
  bulk = Bulk.find(1)
188
188
  ar = bulk.ints
@@ -253,16 +253,16 @@ describe "PgArray" do
253
253
  def map_times(times)
254
254
  times.map{|t| t.strftime("%F %T")}
255
255
  end
256
-
256
+
257
257
  def parse_times(times)
258
258
  times.map{|t| DateTime.parse(t)}
259
259
  end
260
-
260
+
261
261
  def bulks_where(cond)
262
262
  Bulk.where(cond).order('id').all
263
263
  end
264
264
  end
265
-
265
+
266
266
  context "CanCan" do
267
267
  before :all do
268
268
  @ability_class = Class.new do
@@ -270,26 +270,26 @@ describe "PgArray" do
270
270
  end
271
271
  @all_items = Item.all
272
272
  end
273
-
273
+
274
274
  before :each do
275
275
  @ability = @ability_class.new
276
276
  end
277
-
277
+
278
278
  it "should provide search_any for cancan" do
279
279
  should_match_ids_with_ability [2, 3, 4, 6], :tag_ids => [3].search_any
280
280
  should_match_ids_with_ability [1, 3, 4, 5, 6], :tag_ids => [1, 2].search_any
281
281
  end
282
-
282
+
283
283
  it "should provide search_all for cancan" do
284
284
  should_match_ids_with_ability [2, 3, 4, 6], :tag_ids => [3].search_all
285
285
  should_match_ids_with_ability [5, 6], :tag_ids => [1, 2].search_all
286
286
  end
287
-
287
+
288
288
  it "should provide search_subarray for cancan" do
289
289
  should_match_ids_with_ability [2, 7], :tag_ids => [3].search_subarray
290
290
  should_match_ids_with_ability [1, 5, 7], :tag_ids => [1, 2].search_subarray
291
291
  end
292
-
292
+
293
293
  def should_match_ids_with_ability(ids, ability)
294
294
  act = (ability[:tag_ids].class.name + ids.join('_')).to_sym
295
295
  ab.can act, Item, ability
@@ -298,34 +298,34 @@ describe "PgArray" do
298
298
  should_be_able_all items, act
299
299
  should_not_be_able_except items, act
300
300
  end
301
-
301
+
302
302
  def ab
303
303
  @ability
304
304
  end
305
-
305
+
306
306
  def accessible_items(act)
307
307
  Item.accessible_by(ab, act).order('id').all
308
308
  end
309
-
309
+
310
310
  def items_where(cond)
311
311
  Item.where(cond).order('id').all
312
312
  end
313
-
313
+
314
314
  def should_be_able_all(items, act)
315
315
  items.each{|item| ab.should be_able_to(act, item)}
316
316
  end
317
-
317
+
318
318
  def should_not_be_able_except(items, act)
319
319
  (@all_items - items).each{|item| ab.should_not be_able_to(act, items)}
320
320
  end
321
321
  end
322
-
322
+
323
323
  context "references_by" do
324
324
  it "should fetch tags in saved order" do
325
325
  Item.find(3).tags.should == [Tag.find(1), Tag.find(3)]
326
326
  Item.find(4).tags.should == [Tag.find(3), Tag.find(1)]
327
327
  end
328
-
328
+
329
329
  it "should save tags references" do
330
330
  item = Item.find(3)
331
331
  item.tags= [Tag.find(1), '3', 2]
@@ -338,7 +338,7 @@ describe "PgArray" do
338
338
  item.reload
339
339
  item.tags.should == [Tag.find(1), Tag.find(3)]
340
340
  end
341
-
341
+
342
342
  it "should define named scopes for tags" do
343
343
  Item.tags_include(3).order('id').all.should == items_where(:id=>[2,3,4,6])
344
344
  Item.tags_include(1,3).order('id').all.should == items_where(:id=>[3,4,6])
@@ -349,12 +349,12 @@ describe "PgArray" do
349
349
  Item.tags_included_into(3).order('id').all.should == items_where(:id=>[2,7])
350
350
  Item.tags_included_into(1,3).order('id').all.should == items_where(:id=>[1,2,3,4,7])
351
351
  end
352
-
352
+
353
353
  def items_where(cond)
354
354
  Item.where(cond).order('id').all
355
355
  end
356
356
  end
357
-
357
+
358
358
  context "schema" do
359
359
  it "should allow to add column" do
360
360
  lambda do
@@ -366,7 +366,7 @@ describe "PgArray" do
366
366
  end
367
367
  end.should_not raise_error
368
368
  end
369
-
369
+
370
370
  it "should not break other add_column" do
371
371
  lambda do
372
372
  ActiveRecord::Schema.define do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ar_jdbc_pg_array
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: java
7
7
  authors:
8
8
  - Sokolov Yura
@@ -44,6 +44,22 @@ dependencies:
44
44
  none: false
45
45
  prerelease: false
46
46
  type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: json
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ none: false
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ none: false
61
+ prerelease: false
62
+ type: :runtime
47
63
  - !ruby/object:Gem::Dependency
48
64
  name: rake
49
65
  version_requirements: !ruby/object:Gem::Requirement
@@ -116,6 +132,7 @@ extensions: []
116
132
  extra_rdoc_files: []
117
133
  files:
118
134
  - .gitignore
135
+ - .travis.yml
119
136
  - Gemfile
120
137
  - MIT-LICENSE
121
138
  - README.md