rom-sql 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +8 -0
- data/lib/rom/sql/commands.rb +15 -0
- data/lib/rom/sql/version.rb +1 -1
- data/spec/integration/commands/delete_spec.rb +7 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e002fcfac65061b46118390214d8731033307b4
|
4
|
+
data.tar.gz: a13fd979244aee8b7a2c46ef4b522333534ecbd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27e70cf80b500a17af3d29ec60d10c9066caed57256a39f9f7acdc6955999b68d38b18e0356d2ac0518340280651ef5d08d15fd973753050cd66086e0bed2726
|
7
|
+
data.tar.gz: 8b37d7213ff4a0330a3331969886d670a8a09d46dd0cea8145bd45a1959259d44b3fe4dfac5544df6cda76eb0718d6b3406b67d0b7953c90c04c1346ee80bd88
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/rom/sql/commands.rb
CHANGED
@@ -6,7 +6,18 @@ module ROM
|
|
6
6
|
Sequel::NotNullConstraintViolation
|
7
7
|
].freeze
|
8
8
|
|
9
|
+
module TupleCount
|
10
|
+
# TODO: we need an interface for "target_count" here
|
11
|
+
def assert_tuple_count
|
12
|
+
if result == :one && target.count > 1
|
13
|
+
raise TupleCountMismatchError, "#{inspect} expects one tuple"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
9
18
|
class Create < ROM::Commands::Create
|
19
|
+
include TupleCount
|
20
|
+
|
10
21
|
def execute(tuples)
|
11
22
|
pks = Array([tuples]).flatten.map do |tuple|
|
12
23
|
attributes = input[tuple]
|
@@ -21,6 +32,8 @@ module ROM
|
|
21
32
|
end
|
22
33
|
|
23
34
|
class Update < ROM::Commands::Update
|
35
|
+
include TupleCount
|
36
|
+
|
24
37
|
def execute(tuple)
|
25
38
|
attributes = input[tuple]
|
26
39
|
validator.call(attributes)
|
@@ -33,6 +46,8 @@ module ROM
|
|
33
46
|
end
|
34
47
|
|
35
48
|
class Delete < ROM::Commands::Delete
|
49
|
+
include TupleCount
|
50
|
+
|
36
51
|
def execute
|
37
52
|
deleted = target.to_a
|
38
53
|
target.delete
|
data/lib/rom/sql/version.rb
CHANGED
@@ -13,22 +13,24 @@ describe 'Commands / Delete' do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
setup.commands(:users) do
|
16
|
-
define(:delete)
|
16
|
+
define(:delete) do
|
17
|
+
result :one
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
rom.relations.users.insert(id: 2, name: 'Jane')
|
20
22
|
end
|
21
23
|
|
22
|
-
it '
|
24
|
+
it 'raises error when tuple count does not match expectation' do
|
23
25
|
result = users.try { delete }
|
24
26
|
|
25
|
-
expect(result.value.
|
26
|
-
|
27
|
+
expect(result.value).to be(nil)
|
28
|
+
expect(result.error).to be_instance_of(ROM::TupleCountMismatchError)
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'deletes all tuples in a restricted relation' do
|
30
32
|
result = users.try { delete(:by_name, 'Jane') }
|
31
33
|
|
32
|
-
expect(result.value).to
|
34
|
+
expect(result.value).to eql({ id: 2, name: 'Jane' })
|
33
35
|
end
|
34
36
|
end
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|