rom-sql 0.4.0.beta1 → 0.4.0.beta2

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: 43358c16de1cbf1030d10052160c9a5a7e922216
4
- data.tar.gz: 0c9950d51f83c690436f1ba9504435c2bad53d2c
3
+ metadata.gz: c31ac7fa972f7d1fbc7c713386d27022cc23f40d
4
+ data.tar.gz: 01c29d65d87c5938bd54348c012cd081bf4931b2
5
5
  SHA512:
6
- metadata.gz: 916eb01f87b7825519ec9d917ee1904e04fa75537e5e2e35ba470cdc6239f4a0f2037393b64cec97e77fd9f1ea322939cf919e00618a6fff628297bfd1d9ab34
7
- data.tar.gz: d2a3fe1e9077a547b44938c3600d5586548a7a283fa4d46de8c2d73d8b51394f56e8691b88d6197a38de9662c2c3ec697d24ed5415ee48df522010877da70728
6
+ metadata.gz: b80a36a94602f5b5aa5c1ca11ac1b17d7d22d1cb342a682afa6487210ea8d39124062254c7867115bf9d25ccd31c29a795e71b6689529e0a37b404b14a71fc6e
7
+ data.tar.gz: bc46004965aa3c9c8a36d60cd56b23c86c8635efef47e7236905d00ada4647982a90de9693a6c8ca954f1c4de781730efaa9e0829d3ab0605e9ba57cf1681e34
@@ -3,6 +3,8 @@
3
3
  ### Added
4
4
 
5
5
  * `ROM::SQL::Relation` which explictly defines an interface on top of Sequel (solnic + mcls)
6
+ * Postgres-specific Create and Update commands that support RETURNING (gotar + solnic)
7
+ * `Update#change` interface for skipping execution when there's no diff (solnic)
6
8
  * Experimental migration API using sequel/migrations (gotar)
7
9
  * Pagination plugin (solnic)
8
10
 
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
- gem 'rom', '~> 0.6.0', github: 'rom-rb/rom', branch: 'master'
6
+ gem 'rom', '~> 0.6.0.beta', github: 'rom-rb/rom', branch: 'master'
7
7
  gem 'virtus'
8
8
  gem 'activesupport'
9
9
  gem 'rspec', '~> 3.1'
@@ -4,17 +4,16 @@ module ROM
4
4
  module Pagination
5
5
  class Pager
6
6
  include Options
7
- include Equalizer.new(:current_page, :per_page)
7
+ include Equalizer.new(:dataset, :options)
8
8
 
9
9
  option :current_page, reader: true, default: 1
10
10
  option :per_page, reader: true
11
11
 
12
12
  attr_reader :dataset
13
- attr_reader :current_page
14
13
 
15
14
  def initialize(dataset, options = {})
16
- @dataset = dataset
17
15
  super
16
+ @dataset = dataset
18
17
  end
19
18
 
20
19
  def next_page
@@ -35,10 +34,13 @@ module ROM
35
34
  (total / per_page) + 1
36
35
  end
37
36
 
38
- def at(num, per_page = options[:per_page])
37
+ def at(dataset, current_page, per_page = self.per_page)
38
+ current_page = current_page.to_i
39
+ per_page = per_page.to_i
40
+
39
41
  self.class.new(
40
- dataset.offset((num-1)*per_page).limit(per_page),
41
- options.merge(current_page: num, per_page: per_page)
42
+ dataset.offset((current_page-1)*per_page).limit(per_page),
43
+ current_page: current_page, per_page: per_page
42
44
  )
43
45
  end
44
46
 
@@ -70,8 +72,7 @@ module ROM
70
72
  #
71
73
  # @api public
72
74
  def page(num)
73
- num = num.to_i
74
- next_pager = pager.at(num)
75
+ next_pager = pager.at(dataset, num)
75
76
  __new__(next_pager.dataset, pager: next_pager)
76
77
  end
77
78
 
@@ -82,11 +83,9 @@ module ROM
82
83
  #
83
84
  # @api public
84
85
  def per_page(num)
85
- num = num.to_i
86
- next_pager = pager.at(pager.current_page, num)
86
+ next_pager = pager.at(dataset, pager.current_page, num)
87
87
  __new__(next_pager.dataset, pager: next_pager)
88
88
  end
89
-
90
89
  end
91
90
  end
92
91
  end
@@ -125,6 +125,18 @@ module ROM
125
125
  __new__(dataset.__send__(__method__, *args, &block))
126
126
  end
127
127
 
128
+ # Returns a copy of the relation with a SQL DISTINCT clause.
129
+ #
130
+ # @example
131
+ # users.distinct(:country)
132
+ #
133
+ # @return [Relation]
134
+ #
135
+ # @api public
136
+ def distinct(*args, &block)
137
+ __new__(dataset.__send__(__method__, *args, &block))
138
+ end
139
+
128
140
  # Restrict a relation to match criteria
129
141
  #
130
142
  # @example
@@ -137,6 +149,18 @@ module ROM
137
149
  __new__(dataset.__send__(__method__, *args, &block))
138
150
  end
139
151
 
152
+ # Restrict a relation to not match criteria
153
+ #
154
+ # @example
155
+ # users.exclude(name: 'Jane')
156
+ #
157
+ # @return [Relation]
158
+ #
159
+ # @api public
160
+ def exclude(*args, &block)
161
+ __new__(dataset.__send__(__method__, *args, &block))
162
+ end
163
+
140
164
  # Set order for the relation
141
165
  #
142
166
  # @example
@@ -22,7 +22,8 @@ module ROM
22
22
  end
23
23
 
24
24
  def many_to_one(name, options = {})
25
- new_options = options.merge(relation: Inflector.pluralize(name).to_sym)
25
+ relation_name = Inflector.pluralize(name).to_sym
26
+ new_options = options.merge(relation: relation_name)
26
27
  associations << [__method__, name, new_options]
27
28
  end
28
29
 
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module SQL
3
- VERSION = "0.4.0.beta1".freeze
3
+ VERSION = "0.4.0.beta2".freeze
4
4
  end
5
5
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency "sequel", "~> 4.18"
22
22
  spec.add_runtime_dependency "equalizer", "~> 0.0", ">= 0.0.9"
23
- spec.add_runtime_dependency "rom", "~> 0.6.0.beta1"
23
+ spec.add_runtime_dependency "rom", "~> 0.6.0.beta3"
24
24
 
25
25
  spec.add_development_dependency "bundler"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
@@ -37,4 +37,9 @@ shared_context 'database setup' do
37
37
  Integer :task_id
38
38
  end
39
39
  end
40
+
41
+ after do
42
+ rom.repositories[:default].disconnect
43
+ conn.disconnect
44
+ end
40
45
  end
@@ -21,6 +21,12 @@ describe 'Plugin / Pagination' do
21
21
  rom.relation(:users).page('5')
22
22
  }.to_not raise_error
23
23
  end
24
+
25
+ it 'preserves existing modifiers' do
26
+ expect(
27
+ rom.relation(:users) { |r| r.where(name: 'User 2') }.page(1).to_a.size
28
+ ).to be(1)
29
+ end
24
30
  end
25
31
 
26
32
  describe '#per_page' do
@@ -14,6 +14,21 @@ describe ROM::Relation do
14
14
  end
15
15
  end
16
16
 
17
+ describe '#distinct' do
18
+ it 'delegates to dataset and returns a new relation' do
19
+ expect(users.dataset).to receive(:distinct).with(:name).and_call_original
20
+ expect(users.distinct(:name)).to_not eq(users)
21
+ end
22
+ end
23
+
24
+ describe '#exclude' do
25
+ it 'delegates to dataset and returns a new relation' do
26
+ expect(users.dataset)
27
+ .to receive(:exclude).with(name: 'Piotr').and_call_original
28
+ expect(users.exclude(name: 'Piotr')).to_not eq(users)
29
+ end
30
+ end
31
+
17
32
  describe '#map' do
18
33
  it 'yields tuples' do
19
34
  result = []
@@ -24,6 +24,8 @@ describe ROM::SQL::Repository do
24
24
  end
25
25
 
26
26
  describe '#disconnect' do
27
+ let(:repository) { ROM::SQL::Repository.new(uri) }
28
+
27
29
  it 'disconnects via sequel connection' do
28
30
  # FIXME: no idea how to test it in a different way
29
31
  expect(repository.connection).to receive(:disconnect)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.beta1
4
+ version: 0.4.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2015-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.6.0.beta1
53
+ version: 0.6.0.beta3
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: 0.6.0.beta1
60
+ version: 0.6.0.beta3
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: bundler
63
63
  requirement: !ruby/object:Gem::Requirement