Class: MultiInsert::Query::OnConflict
- Inherits:
-
Object
- Object
- MultiInsert::Query::OnConflict
- Defined in:
- lib/multi_insert/query.rb
Overview
A conflict close inside a query.
You never need to instanciate it yourself. Instead, use ‘Query#on_conflict`.
Instance Method Summary collapse
-
#do_nothing ⇒ Query
Ignore conflicting rows.
-
#do_update(values) ⇒ Query
Update the conflicting rows according to user-supplied rules.
-
#initialize(query, column) ⇒ OnConflict
constructor
Create an ON CONFLICT clause.
Constructor Details
#initialize(query, column) ⇒ OnConflict
Create an ON CONFLICT clause
18 19 20 21 |
# File 'lib/multi_insert/query.rb', line 18 def initialize(query, column) @query = query @column = column end |
Instance Method Details
#do_nothing ⇒ Query
Ignore conflicting rows.
26 27 28 |
# File 'lib/multi_insert/query.rb', line 26 def do_nothing @query.on_conflict_sql(::MultiInsert::QueryBuilder.on_conflict_do_nothing(@column)) end |
#do_update(values) ⇒ Query
Update the conflicting rows according to user-supplied rules.
The rules can be:
-
A single symbol or string denoting a column name. In this case, the matching column will be updated.
-
An array of strings or symbols. In this case, the matching columns will be updated.
-
An hash of values (Integers or Strings) or the symbol ‘:excluded`. The matching columns will be updated
to the supplied values, except when the value is ‘:excluded`. In that case, the matching columns will be set to the value to be inserted.
41 42 43 |
# File 'lib/multi_insert/query.rb', line 41 def do_update(values) @query.on_conflict_sql(::MultiInsert::QueryBuilder.on_conflict_do_update(@column, values, @query.opts)) end |