pgrel 0.1.1 → 0.3.1

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/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- local_gemfile = 'Gemfile.local'
6
-
7
- if File.exist?(local_gemfile)
8
- eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval
9
- else
10
- gem 'activerecord', '~>4.0'
11
- end
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
3
- require 'rspec/core/rake_task'
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', "~>4.0"
4
-
5
- gemspec path: '..'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', "~>4.1"
4
-
5
- gemspec path: '..'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', "~>4.2"
4
-
5
- gemspec path: '..'
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'arel', github: 'rails/arel'
4
- gem 'rails', github: 'rails/rails'
5
-
6
- gemspec path: '..'
@@ -1,27 +0,0 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
-
3
- # Maintain your gem's version:
4
- require "pgrel/version"
5
-
6
- # Describe your gem and declare its dependencies:
7
- Gem::Specification.new do |s|
8
- s.name = "pgrel"
9
- s.version = Pgrel::VERSION
10
- s.authors = ["palkan"]
11
- s.email = ["dementiev.vm@gmail.com"]
12
- s.homepage = "http://github.com/palkan/pgrel"
13
- s.summary = "ActiveRecord extension for querying hstore and jsonb."
14
- s.description = "ActiveRecord extension for querying hstore and jsonb."
15
- s.license = "MIT"
16
-
17
- s.files = `git ls-files`.split($/)
18
- s.require_paths = ["lib"]
19
-
20
- s.add_runtime_dependency "activerecord", ">=4.0.0"
21
-
22
- s.add_development_dependency "pg", "~>0.18"
23
- s.add_development_dependency('rake', '~> 10.1')
24
- s.add_development_dependency "simplecov", ">= 0.3.8"
25
- s.add_development_dependency 'pry-byebug'
26
- s.add_development_dependency "rspec", "~> 3.1.0"
27
- end
@@ -1,71 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ArrayStore do
4
- before do
5
- @connection = ActiveRecord::Base.connection
6
-
7
- @connection.transaction do
8
- @connection.create_table('array_stores') do |t|
9
- t.string 'tags', default: [], null: false, array: true
10
- t.string 'name'
11
- end
12
- end
13
-
14
- ArrayStore.reset_column_information
15
- end
16
-
17
- after do
18
- @connection.drop_table 'array_stores', if_exists: true
19
- end
20
-
21
- let!(:setup) do
22
- ArrayStore.create!(name: 'a', tags: [1, 2, 'a', 'b'])
23
- ArrayStore.create!(name: 'b', tags: [2, 'b', 'e'])
24
- ArrayStore.create!(name: 'c', tags: ['b'])
25
- ArrayStore.create!(name: 'd')
26
- ArrayStore.create!(name: 'e', tags: [2, 'x', 'c'])
27
- end
28
-
29
- context '#overlap' do
30
- it "single simple argument" do
31
- records = ArrayStore.where.store(:tags).overlap(:b)
32
- expect(records.size).to eq 3
33
- end
34
-
35
- it "several arguments" do
36
- records = ArrayStore.where.store(:tags).overlap('a', 1)
37
- expect(records.size).to eq 1
38
- expect(records.first.name).to eq 'a'
39
- end
40
-
41
- it "single array argument" do
42
- records = ArrayStore.where.store(:tags).overlap([1, 'x'])
43
- expect(records.size).to eq 2
44
- end
45
- end
46
-
47
- it '#contains' do
48
- records = ArrayStore.where.store(:tags).contains([2, 'b'])
49
- expect(records.size).to eq 2
50
-
51
- records = ArrayStore.where.store(:tags).contains([2, 'x'])
52
- expect(records.size).to eq 1
53
- expect(records.first.name).to eq 'e'
54
- end
55
-
56
- it '#contained' do
57
- records = ArrayStore.where.store(:tags).contained([1, 2, 'a', 'b'])
58
- expect(records.size).to eq 3
59
- expect(records.detect { |r| r.name == 'd' }).not_to be_nil
60
-
61
- records = ArrayStore.where.store(:tags).contained([])
62
- expect(records.size).to eq 1
63
- expect(records.first.name).to eq 'd'
64
- end
65
-
66
- context '#not' do
67
- it '#overlap' do
68
- expect(ArrayStore.where.store(:tags).not.overlap('b', 2).size).to eq 1
69
- end
70
- end
71
- end
@@ -1,130 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hstore do
4
- before do
5
- @connection = ActiveRecord::Base.connection
6
-
7
- @connection.transaction do
8
- @connection.create_table('hstores') do |t|
9
- t.hstore 'tags', default: {}, null: false
10
- t.string 'name'
11
- end
12
- end
13
-
14
- Hstore.reset_column_information
15
- end
16
-
17
- after do
18
- @connection.drop_table 'hstores', if_exists: true
19
- end
20
-
21
- let!(:setup) do
22
- Hstore.create!(name: 'a', tags: { a: 1, b: 2, f: true, d: 'a', g: 'b' })
23
- Hstore.create!(name: 'b', tags: { a: 2, d: 'b', g: 'e' })
24
- Hstore.create!(name: 'c', tags: { f: true, d: 'b' })
25
- Hstore.create!(name: 'd', tags: { f: false })
26
- Hstore.create!(name: 'e', tags: { a: 2, c: 'x', d: 'c', g: 'c' })
27
- Hstore.create!(tags: { 1 => 2 })
28
- end
29
-
30
- context '#where' do
31
- it 'simple values' do
32
- expect(Hstore.where.store(:tags, a: 1, b: 2).first.name).to eq 'a'
33
- expect(Hstore.where.store(:tags, a: 2, c: 'x').first.name).to eq 'e'
34
- expect(Hstore.where.store(:tags, f: false).first.name).to eq 'd'
35
- end
36
-
37
- it 'integer keys' do
38
- expect(Hstore.where.store(:tags, 1 => 2).size).to eq 1
39
- end
40
-
41
- it 'arrays' do
42
- expect(Hstore.where.store(:tags, a: [1, 2, 3]).size).to eq 3
43
- end
44
-
45
- it 'many arrays' do
46
- expect(
47
- Hstore.where.store(
48
- :tags,
49
- a: [1, 2, 3],
50
- c: %w(x y z),
51
- d: %w(a c),
52
- g: %w(b c)
53
- ).size
54
- ).to eq 1
55
- expect(
56
- Hstore.where.store(
57
- :tags,
58
- a: [1, 2, 3],
59
- d: %w(a c),
60
- g: %w(b c)
61
- ).size
62
- ).to eq 2
63
- end
64
- end
65
-
66
- it '#key' do
67
- records = Hstore.where.store(:tags).key(:a)
68
- expect(records.size).to eq 3
69
-
70
- records = Hstore.where.store(:tags).key(:b)
71
- expect(records.size).to eq 1
72
- expect(records.first.name).to eq 'a'
73
- end
74
-
75
- it '#keys' do
76
- records = Hstore.where.store(:tags).keys('a', 'f')
77
- expect(records.size).to eq 1
78
- expect(records.first.name).to eq 'a'
79
-
80
- records = Hstore.where.store(:tags).keys([:a, :c])
81
- expect(records.size).to eq 1
82
- expect(records.first.name).to eq 'e'
83
- end
84
-
85
- it '#any' do
86
- records = Hstore.where.store(:tags).any('b', 'f')
87
- expect(records.size).to eq 3
88
-
89
- records = Hstore.where.store(:tags).any([:c, :b])
90
- expect(records.size).to eq 2
91
- end
92
-
93
- it '#contains' do
94
- records = Hstore.where.store(:tags).contains(f: true)
95
- expect(records.size).to eq 2
96
-
97
- records = Hstore.where.store(:tags).contains(a: 2, c: 'x')
98
- expect(records.size).to eq 1
99
- expect(records.first.name).to eq 'e'
100
- end
101
-
102
- it '#contained' do
103
- records = Hstore.where.store(:tags).contained(
104
- a: 2,
105
- b: 2,
106
- f: true,
107
- d: 'b',
108
- g: 'e'
109
- )
110
- expect(records.size).to eq 2
111
-
112
- records = Hstore.where.store(:tags).contained(c: 'x', f: false)
113
- expect(records.size).to eq 1
114
- expect(records.first.name).to eq 'd'
115
- end
116
-
117
- context '#not' do
118
- it '#where' do
119
- expect(Hstore.where.store(:tags).not(a: 1, g: 'c').size).to eq 1
120
- end
121
-
122
- it '#any' do
123
- expect(Hstore.where.store(:tags).not.any('a', 'f').size).to eq 1
124
- end
125
-
126
- it '#keys' do
127
- expect(Hstore.where.store(:tags).not.keys('a', 'f').size).to eq 5
128
- end
129
- end
130
- end
@@ -1,137 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Jsonb do
4
- before do
5
- @connection = ActiveRecord::Base.connection
6
-
7
- @connection.transaction do
8
- @connection.create_table('jsonbs') do |t|
9
- t.jsonb 'tags', default: {}, null: false
10
- t.string 'name'
11
- end
12
- end
13
-
14
- Jsonb.reset_column_information
15
- end
16
-
17
- after do
18
- @connection.drop_table 'jsonbs', if_exists: true
19
- end
20
-
21
- let!(:setup) do
22
- Jsonb.create!(name: 'a')
23
- Jsonb.create!(name: 'b', tags: { a: 1, d: { e: 2 } })
24
- Jsonb.create!(name: 'c', tags: { a: 2, b: %w(c d) })
25
- Jsonb.create!(name: 'd', tags: { a: 1, b: { c: 'd', e: true } })
26
- Jsonb.create!(name: 'e', tags: { b: 2, c: 'e' })
27
- Jsonb.create!(name: 'f', tags: { d: { e: 1, f: { h: { k: 'a', s: 2 } } } })
28
- end
29
-
30
- context '#where' do
31
- it 'simple values' do
32
- expect(Jsonb.where.store(:tags, b: 2, c: 'e').first.name).to eq 'e'
33
- end
34
-
35
- it 'nested values' do
36
- expect(
37
- Jsonb.where.store(
38
- :tags,
39
- a: 1,
40
- b: { c: 'd', e: true }
41
- ).first.name).to eq 'd'
42
- end
43
-
44
- it 'arrays (as IN)' do
45
- expect(Jsonb.where.store(:tags, a: [1, 2, 3]).size).to eq 3
46
- end
47
- end
48
-
49
- context '#path' do
50
- it 'pass object' do
51
- expect(Jsonb.where.store(:tags).path(b: { c: 'd' }).first.name).to eq 'd'
52
-
53
- expect(
54
- Jsonb.where.store(:tags).path(
55
- d: { f: { h: { s: 2 } } }
56
- ).first.name
57
- ).to eq 'f'
58
- end
59
-
60
- it 'pass array' do
61
- expect(Jsonb.where.store(:tags).path(:b, :c, 'd').first.name).to eq 'd'
62
- end
63
-
64
- it 'match object' do
65
- expect(
66
- Jsonb.where.store(:tags).path(:d, :f, :h, k: 'a', s: 2).first.name
67
- ).to eq 'f'
68
- end
69
-
70
- it 'match array (as IN)' do
71
- expect(Jsonb.where.store(:tags).path(:d, :e, [1, 2]).size).to eq 2
72
- expect(Jsonb.where.store(:tags).path(d: { e: [1, 2] }).size).to eq 2
73
- end
74
- end
75
-
76
- it '#key' do
77
- records = Jsonb.where.store(:tags).key(:a)
78
- expect(records.size).to eq 3
79
-
80
- records = Jsonb.where.store(:tags).key(:c)
81
- expect(records.size).to eq 1
82
- expect(records.first.name).to eq 'e'
83
- end
84
-
85
- it '#keys' do
86
- records = Jsonb.where.store(:tags).keys('a', 'b')
87
- expect(records.size).to eq 2
88
-
89
- records = Jsonb.where.store(:tags).keys([:b, :c])
90
- expect(records.size).to eq 1
91
- expect(records.first.name).to eq 'e'
92
- end
93
-
94
- it '#any' do
95
- records = Jsonb.where.store(:tags).any('a', 'b')
96
- expect(records.size).to eq 4
97
-
98
- records = Jsonb.where.store(:tags).any([:c, :b])
99
- expect(records.size).to eq 3
100
- end
101
-
102
- it '#contains' do
103
- records = Jsonb.where.store(:tags).contains(a: 1)
104
- expect(records.size).to eq 2
105
-
106
- records = Jsonb.where.store(:tags).contains(a: 1, b: { c: 'd' })
107
- expect(records.size).to eq 1
108
- expect(records.first.name).to eq 'd'
109
- end
110
-
111
- it '#contained' do
112
- records = Jsonb.where.store(:tags).contained(
113
- a: 2,
114
- b: 2,
115
- f: true,
116
- c: 'e',
117
- g: 'e'
118
- )
119
- expect(records.size).to eq 2
120
-
121
- records =
122
- Jsonb
123
- .where.store(:tags).key(:a)
124
- .where.store(:tags).contained(a: 2, b: %w(a b c d))
125
-
126
- expect(records.size).to eq 1
127
- expect(records.first.name).to eq 'c'
128
- end
129
-
130
- context '#not' do
131
- it '#path' do
132
- expect(
133
- Jsonb.where.store(:tags).not.path(:d, :f, :h, k: 'a', s: 2).size
134
- ).to eq 0
135
- end
136
- end
137
- end
@@ -1,35 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
-
4
- if ENV['COVER']
5
- require 'simplecov'
6
- SimpleCov.root File.join(File.dirname(__FILE__), '..')
7
- SimpleCov.start
8
- end
9
-
10
- require 'rspec'
11
- require 'pry-byebug'
12
- require 'active_record'
13
- require 'pg'
14
- require 'pgrel'
15
-
16
- ActiveRecord::Base.establish_connection(
17
- adapter: 'postgresql',
18
- host: 'localhost',
19
- username: 'pgrel',
20
- database: 'pgrel'
21
- )
22
- connection = ActiveRecord::Base.connection
23
-
24
- unless connection.extension_enabled?('hstore')
25
- connection.enable_extension 'hstore'
26
- connection.commit_db_transaction
27
- end
28
-
29
- connection.reconnect!
30
-
31
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
32
-
33
- RSpec.configure do |config|
34
- config.mock_with :rspec
35
- end