Sha256: ec4cb67dc4d8b59a6a5787a30974f3e86de0f516727db8ec19cef933a6ccc8ac
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
class Upsert class MergeFunction # @private class SQLite3_Database < MergeFunction attr_reader :quoted_setter_names attr_reader :quoted_selector_names def initialize(*) super @quoted_setter_names = setter_keys.map { |k| connection.quote_ident k } @quoted_selector_names = selector_keys.map { |k| connection.quote_ident k } end def create! # not necessary end def execute(row) bind_setter_values = row.setter.values.map(&:bind_value) insert_or_ignore_sql = %{INSERT OR IGNORE INTO #{quoted_table_name} (#{quoted_setter_names.join(',')}) VALUES (#{Array.new(bind_setter_values.length, '?').join(',')})} connection.execute insert_or_ignore_sql, bind_setter_values update_sql = %{UPDATE #{quoted_table_name} SET #{quoted_setter_names.map { |qk| "#{qk}=?" }.join(',')} WHERE #{quoted_selector_names.map { |qk| "#{qk}=?" }.join(' AND ')}} connection.execute update_sql, (bind_setter_values + row.selector.values.map(&:bind_value)) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
upsert-1.0.2 | lib/upsert/merge_function/SQLite3_Database.rb |