torque-postgresql 2.0.2 → 2.1.0
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.
- checksums.yaml +4 -4
- data/lib/torque/postgresql.rb +1 -0
- data/lib/torque/postgresql/adapter.rb +23 -0
- data/lib/torque/postgresql/adapter/database_statements.rb +2 -0
- data/lib/torque/postgresql/adapter/oid.rb +3 -1
- data/lib/torque/postgresql/adapter/oid/box.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/circle.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/enum.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/enum_set.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/interval.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/line.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/range.rb +2 -0
- data/lib/torque/postgresql/adapter/oid/segment.rb +2 -0
- data/lib/torque/postgresql/adapter/quoting.rb +2 -0
- data/lib/torque/postgresql/adapter/schema_creation.rb +8 -1
- data/lib/torque/postgresql/adapter/schema_definitions.rb +2 -0
- data/lib/torque/postgresql/adapter/schema_dumper.rb +7 -1
- data/lib/torque/postgresql/adapter/schema_statements.rb +2 -0
- data/lib/torque/postgresql/arel/infix_operation.rb +5 -1
- data/lib/torque/postgresql/arel/join_source.rb +2 -0
- data/lib/torque/postgresql/arel/nodes.rb +2 -0
- data/lib/torque/postgresql/arel/operations.rb +2 -0
- data/lib/torque/postgresql/arel/select_manager.rb +2 -0
- data/lib/torque/postgresql/arel/visitors.rb +6 -3
- data/lib/torque/postgresql/associations/association.rb +14 -3
- data/lib/torque/postgresql/associations/association_scope.rb +2 -0
- data/lib/torque/postgresql/associations/belongs_to_many_association.rb +169 -47
- data/lib/torque/postgresql/associations/builder/belongs_to_many.rb +8 -5
- data/lib/torque/postgresql/associations/builder/has_many.rb +2 -0
- data/lib/torque/postgresql/associations/preloader/association.rb +30 -1
- data/lib/torque/postgresql/attributes/builder.rb +3 -1
- data/lib/torque/postgresql/attributes/builder/enum.rb +5 -3
- data/lib/torque/postgresql/attributes/builder/period.rb +6 -4
- data/lib/torque/postgresql/attributes/enum.rb +5 -10
- data/lib/torque/postgresql/attributes/enum_set.rb +2 -0
- data/lib/torque/postgresql/attributes/lazy.rb +3 -1
- data/lib/torque/postgresql/attributes/period.rb +2 -0
- data/lib/torque/postgresql/autosave_association.rb +19 -16
- data/lib/torque/postgresql/auxiliary_statement.rb +2 -0
- data/lib/torque/postgresql/auxiliary_statement/settings.rb +2 -0
- data/lib/torque/postgresql/base.rb +11 -2
- data/lib/torque/postgresql/coder.rb +5 -3
- data/lib/torque/postgresql/collector.rb +2 -0
- data/lib/torque/postgresql/config.rb +5 -0
- data/lib/torque/postgresql/geometry_builder.rb +2 -0
- data/lib/torque/postgresql/i18n.rb +2 -0
- data/lib/torque/postgresql/inheritance.rb +2 -0
- data/lib/torque/postgresql/insert_all.rb +26 -0
- data/lib/torque/postgresql/migration/command_recorder.rb +2 -0
- data/lib/torque/postgresql/railtie.rb +2 -0
- data/lib/torque/postgresql/reflection.rb +2 -0
- data/lib/torque/postgresql/reflection/abstract_reflection.rb +13 -28
- data/lib/torque/postgresql/reflection/association_reflection.rb +24 -0
- data/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb +18 -4
- data/lib/torque/postgresql/reflection/has_many_reflection.rb +2 -0
- data/lib/torque/postgresql/reflection/runtime_reflection.rb +2 -0
- data/lib/torque/postgresql/reflection/through_reflection.rb +2 -0
- data/lib/torque/postgresql/relation.rb +15 -11
- data/lib/torque/postgresql/relation/auxiliary_statement.rb +6 -1
- data/lib/torque/postgresql/relation/distinct_on.rb +2 -0
- data/lib/torque/postgresql/relation/inheritance.rb +2 -0
- data/lib/torque/postgresql/relation/merger.rb +2 -0
- data/lib/torque/postgresql/schema_cache.rb +2 -0
- data/lib/torque/postgresql/version.rb +3 -1
- data/spec/schema.rb +3 -2
- data/spec/tests/arel_spec.rb +3 -1
- data/spec/tests/belongs_to_many_spec.rb +134 -13
- data/spec/tests/enum_set_spec.rb +1 -1
- data/spec/tests/has_many_spec.rb +25 -1
- data/spec/tests/insert_all_spec.rb +89 -0
- data/spec/tests/table_inheritance_spec.rb +1 -1
- metadata +9 -6
data/spec/tests/enum_set_spec.rb
CHANGED
@@ -48,7 +48,7 @@ RSpec.describe 'Enum' do
|
|
48
48
|
expect(dump_io.string).to match checker
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
xit 'can have a default value as an array of symbols' do
|
52
52
|
dump_io = StringIO.new
|
53
53
|
checker = /t\.enum +"types", +default: \[:A, :B\], +array: true, +subtype: :types/
|
54
54
|
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
data/spec/tests/has_many_spec.rb
CHANGED
@@ -5,7 +5,7 @@ RSpec.describe 'HasMany' do
|
|
5
5
|
let(:builder) { ActiveRecord::Associations::Builder::HasMany }
|
6
6
|
|
7
7
|
it 'adds the array option' do
|
8
|
-
expect(builder.send(:valid_options,
|
8
|
+
expect(builder.send(:valid_options, {})).to include(:array)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -21,6 +21,11 @@ RSpec.describe 'HasMany' do
|
|
21
21
|
expect(subject._reflections).to include('texts')
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'has correct foreign key' do
|
25
|
+
item = subject._reflections['texts']
|
26
|
+
expect(item.foreign_key).to be_eql('user_id')
|
27
|
+
end
|
28
|
+
|
24
29
|
it 'loads associated records' do
|
25
30
|
expect(subject.texts.to_sql).to match(Regexp.new(<<-SQL.squish))
|
26
31
|
SELECT "texts"\\.\\* FROM "texts" WHERE \\(?"texts"\\."user_id" = #{subject.id}\\)?
|
@@ -210,6 +215,11 @@ RSpec.describe 'HasMany' do
|
|
210
215
|
expect(subject._reflections).to include('videos')
|
211
216
|
end
|
212
217
|
|
218
|
+
it 'has correct foreign key' do
|
219
|
+
item = subject._reflections['videos']
|
220
|
+
expect(item.foreign_key).to be_eql('tag_ids')
|
221
|
+
end
|
222
|
+
|
213
223
|
it 'loads associated records' do
|
214
224
|
expect(subject.videos.to_sql).to match(Regexp.new(<<-SQL.squish))
|
215
225
|
SELECT "videos"\\.\\* FROM "videos"
|
@@ -281,6 +291,20 @@ RSpec.describe 'HasMany' do
|
|
281
291
|
expect(record.tag_ids).to be_eql([subject.id])
|
282
292
|
end
|
283
293
|
|
294
|
+
it 'can perist after accessed in after_create' do
|
295
|
+
other.belongs_to_many(:tags)
|
296
|
+
other.after_create { self.tags.to_a }
|
297
|
+
|
298
|
+
video = FactoryBot.create(:video)
|
299
|
+
subject.videos << video
|
300
|
+
|
301
|
+
expect(subject.reload.videos.size).to eql(1)
|
302
|
+
expect(video.reload.tags.size).to eql(1)
|
303
|
+
|
304
|
+
other.reset_callbacks(:create)
|
305
|
+
other._reflections = {}
|
306
|
+
end
|
307
|
+
|
284
308
|
it 'can concat records' do
|
285
309
|
FactoryBot.create(:video, tag_ids: [subject.id])
|
286
310
|
expect(subject.videos.size).to be_eql(1)
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'InsertAll' do
|
4
|
+
context 'on executing' do
|
5
|
+
before do
|
6
|
+
ActiveRecord::InsertAll.send(:public, :to_sql)
|
7
|
+
allow_any_instance_of(ActiveRecord::InsertAll).to receive(:execute, &:to_sql)
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { Tag }
|
11
|
+
|
12
|
+
let(:entries) { [{ name: 'A' }, { name: 'B' }] }
|
13
|
+
|
14
|
+
it 'does not mess with insert_all' do
|
15
|
+
result = subject.insert_all(entries)
|
16
|
+
expect(result.squish).to be_eql(<<~SQL.squish)
|
17
|
+
INSERT INTO "tags" ("name") VALUES ('A'), ('B')
|
18
|
+
ON CONFLICT DO NOTHING RETURNING "id"
|
19
|
+
SQL
|
20
|
+
|
21
|
+
result = subject.insert_all(entries, returning: %i[name])
|
22
|
+
expect(result.squish).to be_eql(<<~SQL.squish)
|
23
|
+
INSERT INTO "tags" ("name") VALUES ('A'), ('B')
|
24
|
+
ON CONFLICT DO NOTHING RETURNING "name"
|
25
|
+
SQL
|
26
|
+
|
27
|
+
result = subject.insert_all(entries, returning: %i[id name])
|
28
|
+
expect(result.squish).to be_eql(<<~SQL.squish)
|
29
|
+
INSERT INTO "tags" ("name") VALUES ('A'), ('B')
|
30
|
+
ON CONFLICT DO NOTHING RETURNING "id","name"
|
31
|
+
SQL
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'does not mess with insert_all!' do
|
35
|
+
result = subject.insert_all!(entries)
|
36
|
+
expect(result.squish).to be_eql(<<~SQL.squish)
|
37
|
+
INSERT INTO "tags" ("name") VALUES ('A'), ('B') RETURNING "id"
|
38
|
+
SQL
|
39
|
+
|
40
|
+
result = subject.insert_all!(entries, returning: %i[name])
|
41
|
+
expect(result.squish).to be_eql(<<~SQL.squish)
|
42
|
+
INSERT INTO "tags" ("name") VALUES ('A'), ('B') RETURNING "name"
|
43
|
+
SQL
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'does not mess with upsert without where' do
|
47
|
+
result = subject.upsert_all(entries)
|
48
|
+
expect(result.squish).to be_eql(<<~SQL.squish)
|
49
|
+
INSERT INTO "tags" ("name") VALUES ('A'), ('B')
|
50
|
+
ON CONFLICT ("id") DO UPDATE SET "name"=excluded."name"
|
51
|
+
RETURNING "id"
|
52
|
+
SQL
|
53
|
+
|
54
|
+
result = subject.upsert_all(entries, returning: %i[name])
|
55
|
+
expect(result.squish).to be_eql(<<~SQL.squish)
|
56
|
+
INSERT INTO "tags" ("name") VALUES ('A'), ('B')
|
57
|
+
ON CONFLICT ("id") DO UPDATE SET "name"=excluded."name"
|
58
|
+
RETURNING "name"
|
59
|
+
SQL
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'does add the where condition without the returning clause' do
|
63
|
+
result = subject.upsert_all(entries, returning: false, where: '1=1')
|
64
|
+
expect(result.squish).to be_eql(<<~SQL.squish)
|
65
|
+
INSERT INTO "tags" ("name") VALUES ('A'), ('B')
|
66
|
+
ON CONFLICT ("id") DO UPDATE SET "name"=excluded."name"
|
67
|
+
WHERE 1=1
|
68
|
+
SQL
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'does add the where condition with the returning clause' do
|
72
|
+
result = subject.upsert_all(entries, where: '1=1')
|
73
|
+
expect(result.squish).to be_eql(<<~SQL.squish)
|
74
|
+
INSERT INTO "tags" ("name") VALUES ('A'), ('B')
|
75
|
+
ON CONFLICT ("id") DO UPDATE SET "name"=excluded."name"
|
76
|
+
WHERE 1=1 RETURNING "id"
|
77
|
+
SQL
|
78
|
+
end
|
79
|
+
|
80
|
+
xit 'dows work with model-based where clause' do
|
81
|
+
result = subject.upsert_all(entries, where: Tag.where(name: 'C'))
|
82
|
+
expect(result.squish).to be_eql(<<~SQL.squish)
|
83
|
+
INSERT INTO "tags" ("name") VALUES ('A'), ('B')
|
84
|
+
ON CONFLICT ("id") DO UPDATE SET "name"=excluded."name"
|
85
|
+
WHERE "tags"."name" = 'C' RETURNING "id"
|
86
|
+
SQL
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -66,7 +66,7 @@ RSpec.describe 'TableInheritance' do
|
|
66
66
|
|
67
67
|
it 'allows empty-body create table operation' do
|
68
68
|
sql = connection.create_table(:activity_posts, inherits: :activities)
|
69
|
-
result =
|
69
|
+
result = "CREATE TABLE \"activity_posts\" ()"
|
70
70
|
result << ' INHERITS ( "activities" )'
|
71
71
|
expect(sql).to eql(result)
|
72
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torque-postgresql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -221,6 +221,7 @@ files:
|
|
221
221
|
- lib/torque/postgresql/geometry_builder.rb
|
222
222
|
- lib/torque/postgresql/i18n.rb
|
223
223
|
- lib/torque/postgresql/inheritance.rb
|
224
|
+
- lib/torque/postgresql/insert_all.rb
|
224
225
|
- lib/torque/postgresql/migration.rb
|
225
226
|
- lib/torque/postgresql/migration/command_recorder.rb
|
226
227
|
- lib/torque/postgresql/railtie.rb
|
@@ -277,6 +278,7 @@ files:
|
|
277
278
|
- spec/tests/enum_spec.rb
|
278
279
|
- spec/tests/geometric_builder_spec.rb
|
279
280
|
- spec/tests/has_many_spec.rb
|
281
|
+
- spec/tests/insert_all_spec.rb
|
280
282
|
- spec/tests/interval_spec.rb
|
281
283
|
- spec/tests/lazy_spec.rb
|
282
284
|
- spec/tests/period_spec.rb
|
@@ -333,8 +335,10 @@ test_files:
|
|
333
335
|
- spec/factories/videos.rb
|
334
336
|
- spec/tests/geometric_builder_spec.rb
|
335
337
|
- spec/tests/range_spec.rb
|
338
|
+
- spec/tests/arel_spec.rb
|
339
|
+
- spec/tests/insert_all_spec.rb
|
336
340
|
- spec/tests/enum_spec.rb
|
337
|
-
- spec/tests/
|
341
|
+
- spec/tests/period_spec.rb
|
338
342
|
- spec/tests/coder_spec.rb
|
339
343
|
- spec/tests/collector_spec.rb
|
340
344
|
- spec/tests/distinct_on_spec.rb
|
@@ -342,11 +346,10 @@ test_files:
|
|
342
346
|
- spec/tests/lazy_spec.rb
|
343
347
|
- spec/tests/quoting_spec.rb
|
344
348
|
- spec/tests/relation_spec.rb
|
345
|
-
- spec/tests/
|
349
|
+
- spec/tests/auxiliary_statement_spec.rb
|
346
350
|
- spec/tests/enum_set_spec.rb
|
347
|
-
- spec/tests/belongs_to_many_spec.rb
|
348
351
|
- spec/tests/has_many_spec.rb
|
349
|
-
- spec/tests/
|
352
|
+
- spec/tests/belongs_to_many_spec.rb
|
350
353
|
- spec/tests/table_inheritance_spec.rb
|
351
354
|
- spec/mocks/cache_query.rb
|
352
355
|
- spec/mocks/create_table.rb
|