rom-sql 0.8.0 → 0.9.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/.travis.yml +16 -12
- data/CHANGELOG.md +23 -0
- data/Gemfile +11 -3
- data/README.md +1 -7
- data/lib/rom/sql.rb +4 -7
- data/lib/rom/sql/association.rb +1 -1
- data/lib/rom/sql/association/one_to_many.rb +44 -1
- data/lib/rom/sql/association/one_to_one.rb +1 -38
- data/lib/rom/sql/commands.rb +0 -3
- data/lib/rom/sql/commands/error_wrapper.rb +1 -1
- data/lib/rom/sql/errors.rb +4 -1
- data/lib/rom/sql/extensions.rb +19 -0
- data/lib/rom/sql/{support → extensions}/active_support_notifications.rb +0 -0
- data/lib/rom/sql/extensions/postgres.rb +3 -0
- data/lib/rom/sql/{commands/postgres.rb → extensions/postgres/commands.rb} +38 -0
- data/lib/rom/sql/extensions/postgres/inferrer.rb +64 -0
- data/lib/rom/sql/extensions/postgres/types.rb +65 -0
- data/lib/rom/sql/{support → extensions}/rails_log_subscriber.rb +0 -0
- data/lib/rom/sql/gateway.rb +15 -4
- data/lib/rom/sql/relation.rb +6 -2
- data/lib/rom/sql/relation/reading.rb +18 -0
- data/lib/rom/sql/schema/dsl.rb +7 -4
- data/lib/rom/sql/schema/inferrer.rb +44 -31
- data/lib/rom/sql/types.rb +5 -1
- data/lib/rom/sql/version.rb +1 -1
- data/rom-sql.gemspec +14 -13
- data/spec/extensions/postgres/inferrer_spec.rb +40 -0
- data/spec/extensions/postgres/integration_spec.rb +38 -0
- data/spec/extensions/postgres/types_spec.rb +115 -0
- data/spec/integration/association/many_to_many_spec.rb +2 -1
- data/spec/integration/association/one_to_one_spec.rb +6 -4
- data/spec/integration/combine_spec.rb +1 -1
- data/spec/integration/commands/create_spec.rb +46 -21
- data/spec/integration/commands/delete_spec.rb +13 -38
- data/spec/integration/commands/update_spec.rb +19 -41
- data/spec/integration/commands/upsert_spec.rb +1 -1
- data/spec/integration/gateway_spec.rb +5 -9
- data/spec/integration/migration_spec.rb +6 -7
- data/spec/integration/read_spec.rb +30 -38
- data/spec/integration/schema_inference_spec.rb +211 -49
- data/spec/integration/setup_spec.rb +5 -5
- data/spec/integration/support/active_support_notifications_spec.rb +4 -3
- data/spec/integration/support/rails_log_subscriber_spec.rb +5 -4
- data/spec/shared/database_setup.rb +21 -6
- data/spec/spec_helper.rb +44 -35
- data/spec/unit/association/one_to_many_spec.rb +20 -0
- data/spec/unit/association/one_to_one_spec.rb +23 -2
- data/spec/unit/association_errors_spec.rb +1 -1
- data/spec/unit/gateway_spec.rb +9 -8
- data/spec/unit/logger_spec.rb +1 -1
- data/spec/unit/migration_tasks_spec.rb +3 -3
- data/spec/unit/migrator_spec.rb +3 -2
- data/spec/unit/plugin/assoc_macros/combined_associations_spec.rb +1 -1
- data/spec/unit/plugin/assoc_macros/many_to_many_spec.rb +1 -1
- data/spec/unit/plugin/assoc_macros/many_to_one_spec.rb +1 -1
- data/spec/unit/plugin/assoc_macros/one_to_many_spec.rb +1 -1
- data/spec/unit/relation/associations_spec.rb +27 -0
- data/spec/unit/relation/avg_spec.rb +11 -0
- data/spec/unit/relation/by_pk_spec.rb +15 -0
- data/spec/unit/relation/dataset_spec.rb +48 -0
- data/spec/unit/relation/distinct_spec.rb +14 -0
- data/spec/unit/relation/exclude_spec.rb +13 -0
- data/spec/unit/relation/fetch_spec.rb +21 -0
- data/spec/unit/relation/having_spec.rb +20 -0
- data/spec/unit/relation/inner_join_spec.rb +22 -0
- data/spec/unit/relation/inspect_spec.rb +11 -0
- data/spec/unit/relation/invert_spec.rb +12 -0
- data/spec/unit/relation/left_join_spec.rb +16 -0
- data/spec/unit/relation/map_spec.rb +16 -0
- data/spec/unit/relation/max_spec.rb +11 -0
- data/spec/unit/relation/min_spec.rb +11 -0
- data/spec/unit/relation/pluck_spec.rb +11 -0
- data/spec/unit/relation/prefix_spec.rb +27 -0
- data/spec/unit/relation/primary_key_spec.rb +27 -0
- data/spec/unit/relation/project_spec.rb +22 -0
- data/spec/unit/relation/qualified_columns_spec.rb +27 -0
- data/spec/unit/relation/rename_spec.rb +21 -0
- data/spec/unit/relation/sum_spec.rb +11 -0
- data/spec/unit/relation/union_spec.rb +19 -0
- data/spec/unit/relation/unique_predicate_spec.rb +18 -0
- data/spec/unit/schema_spec.rb +1 -1
- data/spec/unit/types_spec.rb +4 -21
- metadata +79 -11
- data/lib/rom/sql/commands_ext/postgres.rb +0 -45
- data/lib/rom/sql/types/pg.rb +0 -26
- data/spec/unit/relation_spec.rb +0 -272
@@ -0,0 +1,11 @@
|
|
1
|
+
RSpec.describe ROM::Relation, '#pluck' do
|
2
|
+
subject(:relation) { container.relations.users }
|
3
|
+
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
with_adapters do
|
7
|
+
it 'returns a list of values from a specific column' do
|
8
|
+
expect(relation.pluck(:id)).to eql([1, 2])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
RSpec.describe ROM::Relation, '#prefix' do
|
2
|
+
subject(:relation) { container.relations.users }
|
3
|
+
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
before do
|
7
|
+
conf.relation(:users) do
|
8
|
+
def sorted
|
9
|
+
order(:id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
with_adapters do
|
15
|
+
it 'projects the dataset using new column names' do
|
16
|
+
prefixed = relation.sorted.prefix(:user)
|
17
|
+
|
18
|
+
expect(prefixed.first).to eql(user_id: 1, user_name: 'Jane')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'uses singularized table name as the default prefix' do
|
22
|
+
prefixed = relation.sorted.prefix
|
23
|
+
|
24
|
+
expect(prefixed.first).to eql(user_id: 1, user_name: 'Jane')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
RSpec.describe ROM::Relation, '#primary_key' do
|
2
|
+
subject(:relation) { container.relations.users }
|
3
|
+
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
with_adapters do
|
7
|
+
context 'with schema' do
|
8
|
+
it 'returns configured primary key from the schema' do
|
9
|
+
conf.relation(:users) do
|
10
|
+
schema do
|
11
|
+
attribute :name, ROM::SQL::Types::String.meta(primary_key: true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
expect(relation.primary_key).to be(:name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'without schema' do
|
20
|
+
it 'returns :id by default' do
|
21
|
+
conf.relation(:users)
|
22
|
+
|
23
|
+
expect(relation.primary_key).to be(:id)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
RSpec.describe ROM::Relation, '#project' do
|
2
|
+
subject(:relation) { container.relations.users }
|
3
|
+
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
before do
|
7
|
+
conf.relation(:users) do
|
8
|
+
def sorted
|
9
|
+
order(:id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
with_adapters do
|
15
|
+
it 'projects the dataset using new column names' do
|
16
|
+
projected = relation.sorted.project(:name)
|
17
|
+
|
18
|
+
expect(projected.header).to match_array([:name])
|
19
|
+
expect(projected.first).to eql(name: 'Jane')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
RSpec.describe ROM::Relation, '#qualified_columns' do
|
2
|
+
subject(:relation) { container.relations.users }
|
3
|
+
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
before do
|
7
|
+
conf.relation(:users) do
|
8
|
+
def sorted
|
9
|
+
order(:id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
with_adapters do
|
15
|
+
it 'returns qualified column names' do
|
16
|
+
columns = relation.sorted.prefix(:user).qualified_columns
|
17
|
+
|
18
|
+
expect(columns).to eql([:users__id___user_id, :users__name___user_name])
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns projected qualified column names' do
|
22
|
+
columns = relation.sorted.project(:id).prefix(:user).qualified_columns
|
23
|
+
|
24
|
+
expect(columns).to eql([:users__id___user_id])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
RSpec.describe ROM::Relation, '#rename' do
|
2
|
+
subject(:relation) { container.relations.users }
|
3
|
+
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
before do
|
7
|
+
conf.relation(:users) do
|
8
|
+
def sorted
|
9
|
+
order(:id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
with_adapters do
|
15
|
+
it 'projects the dataset using new column names' do
|
16
|
+
renamed = relation.sorted.rename(id: :user_id, name: :user_name)
|
17
|
+
|
18
|
+
expect(renamed.first).to eql(user_id: 1, user_name: 'Jane')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
RSpec.describe ROM::Relation, '#union' do
|
2
|
+
subject(:relation) { container.relations.users }
|
3
|
+
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
with_adapters do
|
7
|
+
let(:relation1) { relation.where(id: 1).select(:id, :name) }
|
8
|
+
let(:relation2) { relation.where(id: 2).select(:id, :name) }
|
9
|
+
|
10
|
+
it 'unions two relations and returns a new relation' do
|
11
|
+
result = relation1.union(relation2)
|
12
|
+
|
13
|
+
expect(result.to_a).to match_array([
|
14
|
+
{ id: 1, name: 'Jane' },
|
15
|
+
{ id: 2, name: 'Joe' }
|
16
|
+
])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
RSpec.describe ROM::Relation, '#unique?' do
|
2
|
+
subject(:relation) { container.relations.tasks }
|
3
|
+
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
with_adapters do
|
7
|
+
before { relation.delete }
|
8
|
+
|
9
|
+
it 'returns true when there is only one tuple matching criteria' do
|
10
|
+
expect(relation.unique?(title: 'Task One')).to be(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns true when there are more than one tuple matching criteria' do
|
14
|
+
relation.insert(title: 'Task One')
|
15
|
+
expect(relation.unique?(title: 'Task One')).to be(false)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/unit/schema_spec.rb
CHANGED
data/spec/unit/types_spec.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'rom/sql/types'
|
2
|
-
require 'rom/sql/types/pg'
|
3
2
|
|
4
|
-
RSpec.describe ROM::SQL::Types do
|
5
|
-
describe ROM::SQL::Types::Serial do
|
3
|
+
RSpec.describe 'ROM::SQL::Types', :postgres do
|
4
|
+
describe 'ROM::SQL::Types::Serial' do
|
6
5
|
it 'accepts ints > 0' do
|
7
6
|
expect(ROM::SQL::Types::Serial[1]).to be(1)
|
8
7
|
end
|
@@ -12,24 +11,8 @@ RSpec.describe ROM::SQL::Types do
|
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
|
-
describe ROM::SQL::Types::
|
16
|
-
it 'coerces to
|
17
|
-
input = { foo: 'bar' }
|
18
|
-
|
19
|
-
expect(ROM::SQL::Types::PG::JSON[input]).to eql(Sequel.pg_json(input))
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'coerces to pg json array' do
|
23
|
-
input = [1, 2, 3]
|
24
|
-
output = ROM::SQL::Types::PG::JSON[input]
|
25
|
-
|
26
|
-
expect(output).to be_instance_of(Sequel::Postgres::JSONArray)
|
27
|
-
expect(output.to_a).to eql(input)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ROM::SQL::Types::PG::Bytea do
|
32
|
-
it 'coerses strings to Sequel::SQL::Blob' do
|
14
|
+
describe ROM::SQL::Types::Blob do
|
15
|
+
it 'coerces strings to Sequel::SQL::Blob' do
|
33
16
|
input = 'sutin'
|
34
17
|
output = described_class[input]
|
35
18
|
|
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
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -44,14 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.9'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dry-core
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.2'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rom
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,12 +155,17 @@ files:
|
|
141
155
|
- lib/rom/sql/commands/create.rb
|
142
156
|
- lib/rom/sql/commands/delete.rb
|
143
157
|
- lib/rom/sql/commands/error_wrapper.rb
|
144
|
-
- lib/rom/sql/commands/postgres.rb
|
145
158
|
- lib/rom/sql/commands/transaction.rb
|
146
159
|
- lib/rom/sql/commands/update.rb
|
147
|
-
- lib/rom/sql/commands_ext/postgres.rb
|
148
160
|
- lib/rom/sql/error.rb
|
149
161
|
- lib/rom/sql/errors.rb
|
162
|
+
- lib/rom/sql/extensions.rb
|
163
|
+
- lib/rom/sql/extensions/active_support_notifications.rb
|
164
|
+
- lib/rom/sql/extensions/postgres.rb
|
165
|
+
- lib/rom/sql/extensions/postgres/commands.rb
|
166
|
+
- lib/rom/sql/extensions/postgres/inferrer.rb
|
167
|
+
- lib/rom/sql/extensions/postgres/types.rb
|
168
|
+
- lib/rom/sql/extensions/rails_log_subscriber.rb
|
150
169
|
- lib/rom/sql/gateway.rb
|
151
170
|
- lib/rom/sql/header.rb
|
152
171
|
- lib/rom/sql/migration.rb
|
@@ -167,14 +186,14 @@ files:
|
|
167
186
|
- lib/rom/sql/schema/dsl.rb
|
168
187
|
- lib/rom/sql/schema/inferrer.rb
|
169
188
|
- lib/rom/sql/spec/support.rb
|
170
|
-
- lib/rom/sql/support/active_support_notifications.rb
|
171
|
-
- lib/rom/sql/support/rails_log_subscriber.rb
|
172
189
|
- lib/rom/sql/tasks/migration_tasks.rake
|
173
190
|
- lib/rom/sql/types.rb
|
174
|
-
- lib/rom/sql/types/pg.rb
|
175
191
|
- lib/rom/sql/version.rb
|
176
192
|
- log/.gitkeep
|
177
193
|
- rom-sql.gemspec
|
194
|
+
- spec/extensions/postgres/inferrer_spec.rb
|
195
|
+
- spec/extensions/postgres/integration_spec.rb
|
196
|
+
- spec/extensions/postgres/types_spec.rb
|
178
197
|
- spec/fixtures/migrations/20150403090603_create_carrots.rb
|
179
198
|
- spec/integration/association/many_to_many_spec.rb
|
180
199
|
- spec/integration/association/many_to_one_spec.rb
|
@@ -219,7 +238,30 @@ files:
|
|
219
238
|
- spec/unit/plugin/assoc_macros/one_to_many_spec.rb
|
220
239
|
- spec/unit/plugin/base_view_spec.rb
|
221
240
|
- spec/unit/plugin/pagination_spec.rb
|
222
|
-
- spec/unit/
|
241
|
+
- spec/unit/relation/associations_spec.rb
|
242
|
+
- spec/unit/relation/avg_spec.rb
|
243
|
+
- spec/unit/relation/by_pk_spec.rb
|
244
|
+
- spec/unit/relation/dataset_spec.rb
|
245
|
+
- spec/unit/relation/distinct_spec.rb
|
246
|
+
- spec/unit/relation/exclude_spec.rb
|
247
|
+
- spec/unit/relation/fetch_spec.rb
|
248
|
+
- spec/unit/relation/having_spec.rb
|
249
|
+
- spec/unit/relation/inner_join_spec.rb
|
250
|
+
- spec/unit/relation/inspect_spec.rb
|
251
|
+
- spec/unit/relation/invert_spec.rb
|
252
|
+
- spec/unit/relation/left_join_spec.rb
|
253
|
+
- spec/unit/relation/map_spec.rb
|
254
|
+
- spec/unit/relation/max_spec.rb
|
255
|
+
- spec/unit/relation/min_spec.rb
|
256
|
+
- spec/unit/relation/pluck_spec.rb
|
257
|
+
- spec/unit/relation/prefix_spec.rb
|
258
|
+
- spec/unit/relation/primary_key_spec.rb
|
259
|
+
- spec/unit/relation/project_spec.rb
|
260
|
+
- spec/unit/relation/qualified_columns_spec.rb
|
261
|
+
- spec/unit/relation/rename_spec.rb
|
262
|
+
- spec/unit/relation/sum_spec.rb
|
263
|
+
- spec/unit/relation/union_spec.rb
|
264
|
+
- spec/unit/relation/unique_predicate_spec.rb
|
223
265
|
- spec/unit/schema_spec.rb
|
224
266
|
- spec/unit/types_spec.rb
|
225
267
|
homepage: http://rom-rb.org
|
@@ -247,6 +289,9 @@ signing_key:
|
|
247
289
|
specification_version: 4
|
248
290
|
summary: SQL databases support for ROM
|
249
291
|
test_files:
|
292
|
+
- spec/extensions/postgres/inferrer_spec.rb
|
293
|
+
- spec/extensions/postgres/integration_spec.rb
|
294
|
+
- spec/extensions/postgres/types_spec.rb
|
250
295
|
- spec/fixtures/migrations/20150403090603_create_carrots.rb
|
251
296
|
- spec/integration/association/many_to_many_spec.rb
|
252
297
|
- spec/integration/association/many_to_one_spec.rb
|
@@ -291,6 +336,29 @@ test_files:
|
|
291
336
|
- spec/unit/plugin/assoc_macros/one_to_many_spec.rb
|
292
337
|
- spec/unit/plugin/base_view_spec.rb
|
293
338
|
- spec/unit/plugin/pagination_spec.rb
|
294
|
-
- spec/unit/
|
339
|
+
- spec/unit/relation/associations_spec.rb
|
340
|
+
- spec/unit/relation/avg_spec.rb
|
341
|
+
- spec/unit/relation/by_pk_spec.rb
|
342
|
+
- spec/unit/relation/dataset_spec.rb
|
343
|
+
- spec/unit/relation/distinct_spec.rb
|
344
|
+
- spec/unit/relation/exclude_spec.rb
|
345
|
+
- spec/unit/relation/fetch_spec.rb
|
346
|
+
- spec/unit/relation/having_spec.rb
|
347
|
+
- spec/unit/relation/inner_join_spec.rb
|
348
|
+
- spec/unit/relation/inspect_spec.rb
|
349
|
+
- spec/unit/relation/invert_spec.rb
|
350
|
+
- spec/unit/relation/left_join_spec.rb
|
351
|
+
- spec/unit/relation/map_spec.rb
|
352
|
+
- spec/unit/relation/max_spec.rb
|
353
|
+
- spec/unit/relation/min_spec.rb
|
354
|
+
- spec/unit/relation/pluck_spec.rb
|
355
|
+
- spec/unit/relation/prefix_spec.rb
|
356
|
+
- spec/unit/relation/primary_key_spec.rb
|
357
|
+
- spec/unit/relation/project_spec.rb
|
358
|
+
- spec/unit/relation/qualified_columns_spec.rb
|
359
|
+
- spec/unit/relation/rename_spec.rb
|
360
|
+
- spec/unit/relation/sum_spec.rb
|
361
|
+
- spec/unit/relation/union_spec.rb
|
362
|
+
- spec/unit/relation/unique_predicate_spec.rb
|
295
363
|
- spec/unit/schema_spec.rb
|
296
364
|
- spec/unit/types_spec.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'rom/sql/commands/create'
|
2
|
-
require 'rom/sql/commands/update'
|
3
|
-
|
4
|
-
module ROM
|
5
|
-
module SQL
|
6
|
-
module Commands
|
7
|
-
module Postgres
|
8
|
-
module Create
|
9
|
-
# Executes insert statement and returns inserted tuples
|
10
|
-
#
|
11
|
-
# @api private
|
12
|
-
def insert(tuples)
|
13
|
-
tuples.map do |tuple|
|
14
|
-
relation.dataset.returning(*relation.columns).insert(tuple)
|
15
|
-
end.flatten
|
16
|
-
end
|
17
|
-
|
18
|
-
# Executes multi_insert statement and returns inserted tuples
|
19
|
-
#
|
20
|
-
# @api private
|
21
|
-
def multi_insert(tuples)
|
22
|
-
relation.dataset.returning(*relation.columns).multi_insert(tuples)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Executes upsert statement (INSERT with ON CONFLICT clause)
|
26
|
-
# and returns inserted/updated tuples
|
27
|
-
#
|
28
|
-
# @api private
|
29
|
-
def upsert(tuple, opts = EMPTY_HASH)
|
30
|
-
relation.dataset.returning(*relation.columns).insert_conflict(opts).insert(tuple)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module Update
|
35
|
-
# Executes update statement and returns updated tuples
|
36
|
-
#
|
37
|
-
# @api private
|
38
|
-
def update(tuple)
|
39
|
-
relation.dataset.returning(*relation.columns).update(tuple)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|