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: 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
79 80 81 |
# File 'lib/rom/sql/relation/writing.rb', line 79 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
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rom/sql/relation/writing.rb', line 113 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
38 39 40 |
# File 'lib/rom/sql/relation/writing.rb', line 38 def insert(*args, &block) dataset.insert(*args, &block) end |
#multi_insert(*args, &block) ⇒ Array<String>
Multi insert tuples into relation
52 53 54 |
# File 'lib/rom/sql/relation/writing.rb', line 52 def multi_insert(*args, &block) dataset.multi_insert(*args, &block) end |
#update(*args, &block) ⇒ Integer
Update tuples in the relation
65 66 67 |
# File 'lib/rom/sql/relation/writing.rb', line 65 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: sequel.jeremyevans.net/rdoc-adapters/classes/Sequel/Postgres/DatasetMethods.html#method-i-insert_conflict
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rom/sql/relation/writing.rb', line 17 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 |