rom-sql 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/lib/rom/sql/association.rb +1 -1
- data/lib/rom/sql/association/many_to_one.rb +1 -1
- data/lib/rom/sql/association/name.rb +1 -1
- data/lib/rom/sql/association/one_to_many.rb +1 -1
- data/lib/rom/sql/attribute.rb +23 -9
- data/lib/rom/sql/dsl.rb +13 -0
- data/lib/rom/sql/extensions/postgres/commands.rb +4 -4
- data/lib/rom/sql/extensions/postgres/types.rb +262 -110
- data/lib/rom/sql/function.rb +2 -2
- data/lib/rom/sql/projection_dsl.rb +1 -12
- data/lib/rom/sql/relation.rb +1 -1
- data/lib/rom/sql/relation/reading.rb +8 -4
- data/lib/rom/sql/restriction_dsl.rb +7 -1
- data/lib/rom/sql/types.rb +2 -0
- data/lib/rom/sql/version.rb +1 -1
- data/spec/extensions/postgres/attribute_spec.rb +78 -0
- data/spec/integration/association/many_to_many/custom_fks_spec.rb +8 -3
- data/spec/integration/association/many_to_many/from_view_spec.rb +9 -3
- data/spec/integration/association/many_to_many_spec.rb +8 -2
- data/spec/integration/association/many_to_one/custom_fks_spec.rb +8 -4
- data/spec/integration/association/many_to_one/from_view_spec.rb +10 -4
- data/spec/integration/association/many_to_one/self_ref_spec.rb +4 -2
- data/spec/integration/association/many_to_one_spec.rb +8 -4
- data/spec/integration/association/one_to_many/custom_fks_spec.rb +5 -2
- data/spec/integration/association/one_to_many/from_view_spec.rb +5 -2
- data/spec/integration/association/one_to_many/self_ref_spec.rb +4 -2
- data/spec/integration/association/one_to_many_spec.rb +1 -1
- data/spec/integration/commands/upsert_spec.rb +2 -2
- data/spec/integration/plugins/auto_wrap_spec.rb +1 -1
- data/spec/integration/sequel_api_spec.rb +3 -2
- data/spec/unit/function_spec.rb +1 -1
- data/spec/unit/order_dsl_spec.rb +4 -4
- data/spec/unit/projection_dsl_spec.rb +8 -0
- data/spec/unit/relation/dataset_spec.rb +3 -3
- data/spec/unit/relation/project_spec.rb +1 -1
- data/spec/unit/relation/qualified_columns_spec.rb +3 -2
- data/spec/unit/relation/where_spec.rb +20 -0
- data/spec/unit/restriction_dsl_spec.rb +2 -2
- metadata +2 -2
@@ -13,7 +13,8 @@ RSpec.describe 'Using legacy sequel api', :sqlite do
|
|
13
13
|
|
14
14
|
describe '#select' do
|
15
15
|
it 'selects columns' do
|
16
|
-
expect(users.select(:
|
16
|
+
expect(users.select(Sequel.qualify(:users, :id), Sequel.qualify(:users, :name)).first).
|
17
|
+
to eql(id: 1, name: 'Jane')
|
17
18
|
end
|
18
19
|
|
19
20
|
it 'supports legacy blocks' do
|
@@ -29,7 +30,7 @@ RSpec.describe 'Using legacy sequel api', :sqlite do
|
|
29
30
|
|
30
31
|
describe '#order' do
|
31
32
|
it 'orders relation' do
|
32
|
-
expect(users.order(:
|
33
|
+
expect(users.order(Sequel.qualify(:users, :name)).first).to eql(id: 1, name: 'Jane')
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
data/spec/unit/function_spec.rb
CHANGED
@@ -24,7 +24,7 @@ RSpec.describe ROM::SQL::Function, :postgres do
|
|
24
24
|
|
25
25
|
describe '#is' do
|
26
26
|
it 'returns an sql boolean expression' do
|
27
|
-
expect((func.count(:id).is(1))
|
27
|
+
expect(ds.literal(func.count(:id).is(1))).to eql(%((COUNT("id") = 1)))
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
data/spec/unit/order_dsl_spec.rb
CHANGED
@@ -17,7 +17,7 @@ RSpec.describe ROM::SQL::OrderDSL, :postgres, helpers: true do
|
|
17
17
|
|
18
18
|
describe '#call' do
|
19
19
|
it 'returns an array with ordered expressions' do
|
20
|
-
expect(dsl.call { id }.first
|
20
|
+
expect(ds.literal(dsl.call { id }.first)).to eql('"id"')
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -28,15 +28,15 @@ RSpec.describe ROM::SQL::OrderDSL, :postgres, helpers: true do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'delegates to sequel virtual row' do
|
31
|
-
expect(dsl.call { nullif(id.qualified,
|
31
|
+
expect(ds.literal(dsl.call { nullif(id.qualified, Sequel.lit("''")).desc }.first)).
|
32
32
|
to eql(%(NULLIF("users"."id", '') DESC))
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'allows to set nulls first/last' do
|
36
|
-
expect(dsl.call { id.desc(nulls: :first) }.first
|
36
|
+
expect(ds.literal(dsl.call { id.desc(nulls: :first) }.first)).
|
37
37
|
to eql(%("id" DESC NULLS FIRST))
|
38
38
|
|
39
|
-
expect(dsl.call { id.desc(nulls: :last) }.first
|
39
|
+
expect(ds.literal(dsl.call { id.desc(nulls: :last) }.first)).
|
40
40
|
to eql(%("id" DESC NULLS LAST))
|
41
41
|
end
|
42
42
|
end
|
@@ -71,6 +71,14 @@ RSpec.describe ROM::SQL::ProjectionDSL, :postgres, helpers: true do
|
|
71
71
|
|
72
72
|
expect(literals).to eql([%('event' AS "type")])
|
73
73
|
end
|
74
|
+
|
75
|
+
it 'supports functions without return value' do
|
76
|
+
literals = dsl
|
77
|
+
.call { void::pg_advisory_lock(1).as(:lock) }
|
78
|
+
.map { |attr| attr.sql_literal(ds) }
|
79
|
+
|
80
|
+
expect(literals).to eql([%(PG_ADVISORY_LOCK(1) AS "lock")])
|
81
|
+
end
|
74
82
|
end
|
75
83
|
|
76
84
|
describe '#method_missing' do
|
@@ -17,7 +17,7 @@ RSpec.describe ROM::Relation, '#dataset' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'uses schema to infer default dataset' do
|
20
|
-
expect(relation.dataset.sql).to eql(dataset.select(:id, :name).order(:
|
20
|
+
expect(relation.dataset.sql).to eql(dataset.select(:id, :name).order(Sequel.qualify(:users, :id)).sql)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -31,7 +31,7 @@ RSpec.describe ROM::Relation, '#dataset' do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'uses schema to infer default dataset' do
|
34
|
-
expect(relation.dataset.sql).to eql(dataset.select(:id).order(:
|
34
|
+
expect(relation.dataset.sql).to eql(dataset.select(:id).order(Sequel.qualify(:users, :id)).sql)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -41,7 +41,7 @@ RSpec.describe ROM::Relation, '#dataset' do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'selects all qualified columns and sorts by pk' do
|
44
|
-
expect(relation.dataset.sql).to eql(dataset.select(*relation.columns).order(:
|
44
|
+
expect(relation.dataset.sql).to eql(dataset.select(*relation.columns).order(Sequel.qualify(:users, :id)).sql)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -17,7 +17,7 @@ RSpec.describe ROM::Relation, '#project' do
|
|
17
17
|
it 'projects the dataset using new column names' do
|
18
18
|
projected = relation.sorted.project(:name)
|
19
19
|
|
20
|
-
expect(projected.schema.map(&:
|
20
|
+
expect(projected.schema.map(&:to_sql_name)).to match_array(Sequel[:name])
|
21
21
|
expect(projected.first).to eql(name: 'Jane')
|
22
22
|
end
|
23
23
|
end
|
@@ -17,13 +17,14 @@ RSpec.describe ROM::Relation, '#qualified_columns' do
|
|
17
17
|
it 'returns qualified column names' do
|
18
18
|
columns = relation.sorted.prefix(:user).qualified_columns
|
19
19
|
|
20
|
-
expect(columns).to eql([:
|
20
|
+
expect(columns).to eql([Sequel.qualify(:users, :id).as(:user_id),
|
21
|
+
Sequel.qualify(:users, :name).as(:user_name)])
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'returns projected qualified column names' do
|
24
25
|
columns = relation.sorted.project(:id).prefix(:user).qualified_columns
|
25
26
|
|
26
|
-
expect(columns).to eql([:
|
27
|
+
expect(columns).to eql([Sequel.qualify(:users, :id).as(:user_id)])
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
@@ -49,6 +49,26 @@ RSpec.describe ROM::Relation, '#where' do
|
|
49
49
|
expect(relation.where(relation[:id].in(2, 3)).to_a).
|
50
50
|
to eql([{ id: 2, title: "Jane's task" }])
|
51
51
|
end
|
52
|
+
|
53
|
+
context 'using underscored symbols for qualifying' do
|
54
|
+
before { Sequel.split_symbols = true }
|
55
|
+
after { Sequel.split_symbols = false }
|
56
|
+
|
57
|
+
it 'queries with a qualified name' do
|
58
|
+
expect(relation.where(tasks__id: 1).to_a).
|
59
|
+
to eql([{ id: 1, title: "Joe's task" }])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'restricts with a function' do
|
64
|
+
expect(relation.where { string::lower(title).is("joe's task") }.to_a).
|
65
|
+
to eql([{ id: 1, title: "Joe's task" }])
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'restricts with a function using LIKE' do
|
69
|
+
expect(relation.where { string::lower(title).like("joe%") }.to_a).
|
70
|
+
to eql([{ id: 1, title: "Joe's task" }])
|
71
|
+
end
|
52
72
|
end
|
53
73
|
|
54
74
|
context 'with :read types' do
|
@@ -17,7 +17,7 @@ RSpec.describe ROM::SQL::RestrictionDSL, :sqlite, helpers: true do
|
|
17
17
|
|
18
18
|
describe '#call' do
|
19
19
|
it 'evaluates the block and returns an SQL expression' do
|
20
|
-
expect(dsl.call { count(id) >= 3 }
|
20
|
+
expect(conn[:users].literal(dsl.call { count(id) >= 3 })).to eql('(count(`id`) >= 3)')
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -28,7 +28,7 @@ RSpec.describe ROM::SQL::RestrictionDSL, :sqlite, helpers: true do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'delegates to sequel virtual row' do
|
31
|
-
expect(dsl.count(dsl.id)
|
31
|
+
expect(conn[:users].literal(dsl.count(dsl.id))).to eql('count(`id`)')
|
32
32
|
end
|
33
33
|
end
|
34
34
|
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: 1.3.
|
4
|
+
version: 1.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: 2017-05-
|
11
|
+
date: 2017-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|