surus 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -82
- data/bench/benchmark_helper.rb +0 -9
- data/bench/database_structure.sql +0 -18
- data/bench/hstore_find.rb +7 -7
- data/bench/json_generation.rb +1 -1
- data/lib/surus.rb +0 -6
- data/lib/surus/array/scope.rb +1 -1
- data/lib/surus/hstore/serializer.rb +23 -47
- data/lib/surus/json/belongs_to_scope_builder.rb +3 -3
- data/lib/surus/json/has_and_belongs_to_many_scope_builder.rb +4 -5
- data/lib/surus/json/has_many_scope_builder.rb +3 -4
- data/lib/surus/json/model.rb +1 -1
- data/lib/surus/version.rb +1 -1
- data/spec/array/scope_spec.rb +6 -6
- data/spec/hstore/scope_spec.rb +21 -21
- data/spec/spec_helper.rb +6 -20
- data/surus.gemspec +1 -1
- metadata +5 -24
- data/bench/array_create.rb +0 -46
- data/bench/array_find.rb +0 -79
- data/bench/array_serialize.rb +0 -34
- data/bench/hstore_create.rb +0 -57
- data/bench/hstore_serialize.rb +0 -42
- data/lib/surus/array/decimal_serializer.rb +0 -28
- data/lib/surus/array/float_serializer.rb +0 -28
- data/lib/surus/array/integer_serializer.rb +0 -28
- data/lib/surus/array/text_serializer.rb +0 -47
- data/lib/surus/hstore/connection_adapters.rb +0 -46
- data/lib/surus/json/connection_adapters.rb +0 -46
- data/spec/array/decimal_serializer_spec.rb +0 -23
- data/spec/array/float_serializer_spec.rb +0 -23
- data/spec/array/integer_serializer_spec.rb +0 -22
- data/spec/array/text_serializer_spec.rb +0 -29
@@ -2,12 +2,11 @@ module Surus
|
|
2
2
|
module JSON
|
3
3
|
class HasManyScopeBuilder < AssociationScopeBuilder
|
4
4
|
def scope
|
5
|
-
|
5
|
+
s = association
|
6
6
|
.klass
|
7
7
|
.where("#{outside_primary_key}=#{association_foreign_key}")
|
8
|
-
|
9
|
-
|
10
|
-
association_scope
|
8
|
+
s = s.instance_eval(&association.scope) if association.scope
|
9
|
+
s
|
11
10
|
end
|
12
11
|
|
13
12
|
def outside_primary_key
|
data/lib/surus/json/model.rb
CHANGED
data/lib/surus/version.rb
CHANGED
data/spec/array/scope_spec.rb
CHANGED
@@ -14,17 +14,17 @@ describe Surus::Array::Scope do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
context "with one element" do
|
17
|
-
subject { TextArrayRecord.array_has(:texts, "b")
|
17
|
+
subject { TextArrayRecord.array_has(:texts, "b") }
|
18
18
|
shared_examples
|
19
19
|
end
|
20
20
|
|
21
21
|
context "with array of elements" do
|
22
|
-
subject { TextArrayRecord.array_has(:texts, ["a", "b"])
|
22
|
+
subject { TextArrayRecord.array_has(:texts, ["a", "b"]) }
|
23
23
|
shared_examples
|
24
24
|
end
|
25
25
|
|
26
26
|
context "with multiple elements" do
|
27
|
-
subject { TextArrayRecord.array_has(:texts, "a", "b")
|
27
|
+
subject { TextArrayRecord.array_has(:texts, "a", "b") }
|
28
28
|
shared_examples
|
29
29
|
end
|
30
30
|
end
|
@@ -40,17 +40,17 @@ describe Surus::Array::Scope do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
context "with one element" do
|
43
|
-
subject { TextArrayRecord.array_has_any(:texts, "b")
|
43
|
+
subject { TextArrayRecord.array_has_any(:texts, "b") }
|
44
44
|
shared_examples
|
45
45
|
end
|
46
46
|
|
47
47
|
context "with array of elements" do
|
48
|
-
subject { TextArrayRecord.array_has_any(:texts, ["b", "c"])
|
48
|
+
subject { TextArrayRecord.array_has_any(:texts, ["b", "c"]) }
|
49
49
|
shared_examples
|
50
50
|
end
|
51
51
|
|
52
52
|
context "with multiple elements" do
|
53
|
-
subject { TextArrayRecord.array_has_any(:texts, "b", "c")
|
53
|
+
subject { TextArrayRecord.array_has_any(:texts, "b", "c") }
|
54
54
|
shared_examples
|
55
55
|
end
|
56
56
|
end
|
data/spec/hstore/scope_spec.rb
CHANGED
@@ -7,69 +7,69 @@ describe Surus::Hstore::Scope do
|
|
7
7
|
let!(:match) { HstoreRecord.create! :properties => { "a" => "1", "b" => "2", "c" => "3" } }
|
8
8
|
let!(:missing_key) { HstoreRecord.create! :properties => { "a" => "1", "c" => "3" } }
|
9
9
|
let!(:wrong_value) { HstoreRecord.create! :properties => { "a" => "1", "b" => "5" } }
|
10
|
-
|
11
|
-
subject { HstoreRecord.hstore_has_pairs(:properties, "a" => "1", "b" => "2")
|
12
|
-
|
10
|
+
|
11
|
+
subject { HstoreRecord.hstore_has_pairs(:properties, "a" => "1", "b" => "2") }
|
12
|
+
|
13
13
|
it { should include(match) }
|
14
14
|
it { should_not include(missing_key) }
|
15
15
|
it { should_not include(wrong_value) }
|
16
16
|
it { should_not include(empty) }
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
context "hstore_has_key" do
|
20
20
|
let!(:match) { HstoreRecord.create! :properties => { "a" => "1", "b" => "2" } }
|
21
21
|
let!(:missing_key) { HstoreRecord.create! :properties => { "a" => "1", "c" => "3" } }
|
22
|
-
|
23
|
-
subject { HstoreRecord.hstore_has_key(:properties, "b")
|
22
|
+
|
23
|
+
subject { HstoreRecord.hstore_has_key(:properties, "b") }
|
24
24
|
|
25
25
|
it { should include(match) }
|
26
26
|
it { should_not include(missing_key) }
|
27
27
|
it { should_not include(empty) }
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
context "hstore_has_all_keys" do
|
31
31
|
let!(:match) { HstoreRecord.create! :properties => { "a" => "1", "b" => "2", "c" => "3" } }
|
32
32
|
let!(:missing_one_key) { HstoreRecord.create! :properties => { "b" => "2", "c" => "3" } }
|
33
33
|
let!(:missing_all_keys) { HstoreRecord.create! :properties => { "f" => "1", "g" => "2" } }
|
34
|
-
|
34
|
+
|
35
35
|
def self.shared_examples
|
36
36
|
it { should include(match) }
|
37
37
|
it { should_not include(missing_one_key) }
|
38
38
|
it { should_not include(missing_all_keys) }
|
39
|
-
it { should_not include(empty) }
|
39
|
+
it { should_not include(empty) }
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
context "with array of keys" do
|
43
|
-
subject { HstoreRecord.hstore_has_all_keys(:properties, ["a", "b"])
|
43
|
+
subject { HstoreRecord.hstore_has_all_keys(:properties, ["a", "b"]) }
|
44
44
|
shared_examples
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
context "with multiple key arguments" do
|
48
|
-
subject { HstoreRecord.hstore_has_all_keys(:properties, "a", "b")
|
48
|
+
subject { HstoreRecord.hstore_has_all_keys(:properties, "a", "b") }
|
49
49
|
shared_examples
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
context "hstore_has_any_key" do
|
54
54
|
let!(:match_1) { HstoreRecord.create! :properties => { "a" => "1", "c" => "3" } }
|
55
55
|
let!(:match_2) { HstoreRecord.create! :properties => { "b" => "2", "d" => "4" } }
|
56
56
|
let!(:missing_all_keys) { HstoreRecord.create! :properties => { "c" => "3", "d" => "4" } }
|
57
|
-
|
57
|
+
|
58
58
|
def self.shared_examples
|
59
59
|
it { should include(match_1) }
|
60
60
|
it { should include(match_2) }
|
61
61
|
it { should_not include(missing_all_keys) }
|
62
|
-
it { should_not include(empty) }
|
63
|
-
it { should_not include(empty) }
|
62
|
+
it { should_not include(empty) }
|
63
|
+
it { should_not include(empty) }
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
context "with array of keys" do
|
67
|
-
subject { HstoreRecord.hstore_has_any_keys(:properties, ["a", "b"])
|
67
|
+
subject { HstoreRecord.hstore_has_any_keys(:properties, ["a", "b"]) }
|
68
68
|
shared_examples
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
context "with multiple key arguments" do
|
72
|
-
subject { HstoreRecord.hstore_has_any_keys(:properties, "a", "b")
|
72
|
+
subject { HstoreRecord.hstore_has_any_keys(:properties, "a", "b") }
|
73
73
|
shared_examples
|
74
74
|
end
|
75
75
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,35 +12,21 @@ class HstoreRecord < ActiveRecord::Base
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class TextArrayRecord < ActiveRecord::Base
|
15
|
-
serialize :texts, Surus::Array::TextSerializer.new
|
16
15
|
end
|
17
16
|
|
18
17
|
class VarcharArrayRecord < ActiveRecord::Base
|
19
|
-
serialize :varchars, Surus::Array::TextSerializer.new
|
20
|
-
end
|
21
|
-
|
22
|
-
class IntegerArrayRecord < ActiveRecord::Base
|
23
|
-
serialize :integers, Surus::Array::IntegerSerializer.new
|
24
|
-
end
|
25
|
-
|
26
|
-
class FloatArrayRecord < ActiveRecord::Base
|
27
|
-
serialize :floats, Surus::Array::FloatSerializer.new
|
28
|
-
end
|
29
|
-
|
30
|
-
class DecimalArrayRecord < ActiveRecord::Base
|
31
|
-
serialize :decimals, Surus::Array::DecimalSerializer.new
|
32
18
|
end
|
33
19
|
|
34
20
|
class User < ActiveRecord::Base
|
35
21
|
has_many :posts, foreign_key: :author_id
|
36
22
|
has_many :posts_with_order,
|
23
|
+
-> { order 'posts.id desc' },
|
37
24
|
foreign_key: :author_id,
|
38
|
-
class_name: 'Post'
|
39
|
-
order: 'posts.id desc'
|
25
|
+
class_name: 'Post'
|
40
26
|
has_many :posts_with_conditions,
|
27
|
+
-> { where subject: 'foo' },
|
41
28
|
foreign_key: :author_id,
|
42
|
-
class_name: 'Post'
|
43
|
-
conditions: {subject: 'foo'}
|
29
|
+
class_name: 'Post'
|
44
30
|
end
|
45
31
|
|
46
32
|
class Forum < ActiveRecord::Base
|
@@ -51,9 +37,9 @@ class Post < ActiveRecord::Base
|
|
51
37
|
belongs_to :forum
|
52
38
|
belongs_to :author, class_name: 'User'
|
53
39
|
belongs_to :forum_with_impossible_conditions,
|
40
|
+
-> { where '1=2' },
|
54
41
|
foreign_key: :forum_id,
|
55
|
-
class_name: 'Forum'
|
56
|
-
conditions: '1=2'
|
42
|
+
class_name: 'Forum'
|
57
43
|
has_and_belongs_to_many :tags
|
58
44
|
end
|
59
45
|
|
data/surus.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.require_paths = ["lib"]
|
24
24
|
|
25
25
|
# specify any dependencies here; for example:
|
26
|
-
s.add_dependency 'activerecord', "~>
|
26
|
+
s.add_dependency 'activerecord', "~> 4.0"
|
27
27
|
|
28
28
|
s.add_development_dependency 'rspec', "~> 2.12.0"
|
29
29
|
s.add_development_dependency 'guard', ">= 0.10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Christensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,32 +169,21 @@ files:
|
|
169
169
|
- LICENSE
|
170
170
|
- README.md
|
171
171
|
- Rakefile
|
172
|
-
- bench/array_create.rb
|
173
|
-
- bench/array_find.rb
|
174
|
-
- bench/array_serialize.rb
|
175
172
|
- bench/benchmark_helper.rb
|
176
173
|
- bench/database.yml
|
177
174
|
- bench/database_structure.sql
|
178
|
-
- bench/hstore_create.rb
|
179
175
|
- bench/hstore_find.rb
|
180
|
-
- bench/hstore_serialize.rb
|
181
176
|
- bench/json_generation.rb
|
182
177
|
- bench/synchronous_commit.rb
|
183
178
|
- lib/generators/surus/hstore/install_generator.rb
|
184
179
|
- lib/generators/surus/hstore/templates/install_hstore.rb
|
185
180
|
- lib/surus.rb
|
186
|
-
- lib/surus/array/decimal_serializer.rb
|
187
|
-
- lib/surus/array/float_serializer.rb
|
188
|
-
- lib/surus/array/integer_serializer.rb
|
189
181
|
- lib/surus/array/scope.rb
|
190
|
-
- lib/surus/array/text_serializer.rb
|
191
|
-
- lib/surus/hstore/connection_adapters.rb
|
192
182
|
- lib/surus/hstore/scope.rb
|
193
183
|
- lib/surus/hstore/serializer.rb
|
194
184
|
- lib/surus/json/array_agg_query.rb
|
195
185
|
- lib/surus/json/association_scope_builder.rb
|
196
186
|
- lib/surus/json/belongs_to_scope_builder.rb
|
197
|
-
- lib/surus/json/connection_adapters.rb
|
198
187
|
- lib/surus/json/has_and_belongs_to_many_scope_builder.rb
|
199
188
|
- lib/surus/json/has_many_scope_builder.rb
|
200
189
|
- lib/surus/json/model.rb
|
@@ -203,11 +192,7 @@ files:
|
|
203
192
|
- lib/surus/synchronous_commit/connection.rb
|
204
193
|
- lib/surus/synchronous_commit/model.rb
|
205
194
|
- lib/surus/version.rb
|
206
|
-
- spec/array/decimal_serializer_spec.rb
|
207
|
-
- spec/array/float_serializer_spec.rb
|
208
|
-
- spec/array/integer_serializer_spec.rb
|
209
195
|
- spec/array/scope_spec.rb
|
210
|
-
- spec/array/text_serializer_spec.rb
|
211
196
|
- spec/database.yml
|
212
197
|
- spec/database_structure.sql
|
213
198
|
- spec/factories.rb
|
@@ -238,16 +223,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
238
223
|
version: '0'
|
239
224
|
requirements: []
|
240
225
|
rubyforge_project: ''
|
241
|
-
rubygems_version: 2.0.
|
226
|
+
rubygems_version: 2.0.3
|
242
227
|
signing_key:
|
243
228
|
specification_version: 4
|
244
229
|
summary: PostgreSQL Acceleration for ActiveRecord
|
245
230
|
test_files:
|
246
|
-
- spec/array/decimal_serializer_spec.rb
|
247
|
-
- spec/array/float_serializer_spec.rb
|
248
|
-
- spec/array/integer_serializer_spec.rb
|
249
231
|
- spec/array/scope_spec.rb
|
250
|
-
- spec/array/text_serializer_spec.rb
|
251
232
|
- spec/database.yml
|
252
233
|
- spec/database_structure.sql
|
253
234
|
- spec/factories.rb
|
data/bench/array_create.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'benchmark_helper'
|
2
|
-
|
3
|
-
options = {}
|
4
|
-
optparse = OptionParser.new do |opts|
|
5
|
-
options[:records] = 1000
|
6
|
-
opts.on '-r NUM', '--records NUM', Integer, 'Number of records to create' do |n|
|
7
|
-
options[:records] = n
|
8
|
-
end
|
9
|
-
|
10
|
-
options[:elements] = 10
|
11
|
-
opts.on '-e NUM', '--elements NUM', Integer, 'Number of elements' do |n|
|
12
|
-
options[:elements] = n
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
optparse.parse!
|
17
|
-
|
18
|
-
clean_database
|
19
|
-
|
20
|
-
num_records = options[:records]
|
21
|
-
num_elements = options[:elements]
|
22
|
-
|
23
|
-
arrays = num_records.times.map do
|
24
|
-
num_elements.times.map { SecureRandom.hex(4) }
|
25
|
-
end
|
26
|
-
|
27
|
-
puts
|
28
|
-
puts "Writing #{num_records} records with a #{num_elements} element string array"
|
29
|
-
|
30
|
-
Benchmark.bm(8) do |x|
|
31
|
-
x.report("Surus") do
|
32
|
-
SurusKeyValueRecord.transaction do
|
33
|
-
num_records.times do |i|
|
34
|
-
SurusTextArrayRecord.create! :names => arrays[i]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
x.report("YAML") do
|
40
|
-
YamlKeyValueRecord.transaction do
|
41
|
-
num_records.times do |i|
|
42
|
-
YamlArrayRecord.create! :names => arrays[i]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/bench/array_find.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'benchmark_helper'
|
2
|
-
|
3
|
-
options = {}
|
4
|
-
optparse = OptionParser.new do |opts|
|
5
|
-
options[:records] = 2_000
|
6
|
-
opts.on '-r NUM', '--records NUM', Integer, 'Number of records to create' do |n|
|
7
|
-
options[:records] = n
|
8
|
-
end
|
9
|
-
|
10
|
-
options[:elements] = 10
|
11
|
-
opts.on '-e NUM', '--elements NUM', Integer, 'Number of elements per array' do |n|
|
12
|
-
options[:elements] = n
|
13
|
-
end
|
14
|
-
|
15
|
-
options[:finds] = 200
|
16
|
-
opts.on '-f NUM', '--finds NUM', Integer, 'Number of finds to perform' do |n|
|
17
|
-
options[:finds] = n
|
18
|
-
end
|
19
|
-
|
20
|
-
options[:yaml] = false
|
21
|
-
opts.on '-y', '--yaml', 'Include YAML in benchmark (VERY SLOW!)' do
|
22
|
-
options[:yaml] = true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
optparse.parse!
|
27
|
-
|
28
|
-
clean_database
|
29
|
-
|
30
|
-
num_records = options[:records]
|
31
|
-
num_elements = options[:elements]
|
32
|
-
num_finds = options[:finds]
|
33
|
-
yaml = options[:yaml]
|
34
|
-
|
35
|
-
puts "Skipping YAML test. Use -y to enable (VERY SLOW!)" unless yaml
|
36
|
-
|
37
|
-
arrays = num_records.times.map do
|
38
|
-
num_elements.times.map { SecureRandom.hex(4) }
|
39
|
-
end
|
40
|
-
|
41
|
-
print "Creating Surus test data... "
|
42
|
-
SurusKeyValueRecord.transaction do
|
43
|
-
num_records.times do |i|
|
44
|
-
SurusTextArrayRecord.create! :names => arrays[i]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
puts "Done."
|
48
|
-
|
49
|
-
if yaml
|
50
|
-
print "Creating YAML test data... "
|
51
|
-
YamlArrayRecord.transaction do
|
52
|
-
num_records.times do |i|
|
53
|
-
YamlArrayRecord.create! :names => arrays[i]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
puts "Done."
|
57
|
-
end
|
58
|
-
|
59
|
-
puts
|
60
|
-
puts "#{num_records} records with #{num_elements} element arrays"
|
61
|
-
puts "Finding all where array includes value #{num_finds} times"
|
62
|
-
|
63
|
-
values_to_find = arrays.sample(num_finds).map { |a| a.sample }
|
64
|
-
|
65
|
-
Benchmark.bm(8) do |x|
|
66
|
-
x.report("Surus") do
|
67
|
-
values_to_find.each do |value_to_find|
|
68
|
-
SurusTextArrayRecord.array_has(:names, value_to_find).all
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
if yaml
|
73
|
-
x.report("YAML") do
|
74
|
-
values_to_find.each do |value_to_find|
|
75
|
-
YamlArrayRecord.all.select { |r| r.names.include?(value_to_find) }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|