Module: ROM::SQL::Relation::Writing
- Included in:
- ROM::SQL::Relation
- Defined in:
- lib/rom/sql/relation/writing.rb
Instance Method Summary collapse
-
#delete(*args, &block) ⇒ Integer
Delete tuples from the relation.
-
#import(other, options = EMPTY_HASH) ⇒ Integer
Insert tuples from other relation.
-
#insert(*args, &block) ⇒ Hash
Insert tuple into relation.
-
#multi_insert(*args, &block) ⇒ Array<String>
Multi insert tuples into relation.
-
#update(*args, &block) ⇒ Integer
Update tuples in the relation.
-
#upsert(*args, &block) ⇒ Integer
Add upsert option (only PostgreSQL >= 9.5) Uses internal Sequel implementation Default - ON CONFLICT DO NOTHING more options: http://sequel.jeremyevans.net/rdoc-adapters/classes/Sequel/Postgres/DatasetMethods.html#method-i-insert_conflict.
Instance Method Details
#delete(*args, &block) ⇒ Integer
Delete tuples from the relation
81 82 83 |
# File 'lib/rom/sql/relation/writing.rb', line 81 def delete(*args, &block) dataset.delete(*args, &block) end |
#import(other_sql_relation, options) ⇒ Integer #import(other, options) ⇒ Integer
Insert tuples from other relation
NOTE: The method implicitly uses a transaction
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/rom/sql/relation/writing.rb', line 115 def import(other, = EMPTY_HASH) if other.gateway.eql?(gateway) columns = other.schema.map { |a| a.alias || a.name } dataset.import(columns, other.dataset, ) else columns = other.schema.map { |a| a.alias || a.name } keys = columns.map(&:to_sym) dataset.import(columns, other.to_a.map { |record| record.to_h.values_at(*keys) }, ) end end |
#insert(*args, &block) ⇒ Hash
Insert tuple into relation
40 41 42 |
# File 'lib/rom/sql/relation/writing.rb', line 40 def insert(*args, &block) dataset.insert(*args, &block) end |
#multi_insert(*args, &block) ⇒ Array<String>
Multi insert tuples into relation
54 55 56 |
# File 'lib/rom/sql/relation/writing.rb', line 54 def multi_insert(*args, &block) dataset.multi_insert(*args, &block) end |
#update(*args, &block) ⇒ Integer
Update tuples in the relation
67 68 69 |
# File 'lib/rom/sql/relation/writing.rb', line 67 def update(*args, &block) dataset.update(*args, &block) end |
#upsert(*args, &block) ⇒ Integer
Add upsert option (only PostgreSQL >= 9.5) Uses internal Sequel implementation Default - ON CONFLICT DO NOTHING more options: http://sequel.jeremyevans.net/rdoc-adapters/classes/Sequel/Postgres/DatasetMethods.html#method-i-insert_conflict
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rom/sql/relation/writing.rb', line 19 def upsert(*args, &block) if args.size > 1 && args[-1].is_a?(Hash) *values, opts = args else values = args opts = EMPTY_HASH end dataset.insert_conflict(opts).insert(*values, &block) end |