Sha256: 8b03dd2fb13c5811cab856f66798f31bea6f6df9d359ef83e85c6e7b9e0726fb

Contents?: true

Size: 735 Bytes

Versions: 15

Compression:

Stored size: 735 Bytes

Contents

class Baza::SqlQueries::GenericUpdate
  def initialize(args)
    @db = args.fetch(:db)
    @table_name = args.fetch(:table_name)
    @data = args.fetch(:data)
    @terms = args.fetch(:terms)
    @buffer = args[:buffer]
  end

  def execute
    if @buffer
      @buffer.query(to_sql)
    else
      @db.query(to_sql)
    end
  end

  def to_sql
    sql = "UPDATE #{@db.sep_col}#{@db.escape_table(@table_name)}#{@db.sep_col} SET "

    first = true
    @data.each do |key, value|
      sql << ", " unless first
      first = false if first
      sql << "#{@db.sep_col}#{@db.escape_column(key)}#{@db.sep_col} = #{@db.sqlval(value)}"
    end

    sql << " WHERE #{@db.sql_make_where(@terms)}" if @terms && !@terms.empty?
    sql
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
baza-0.0.35 lib/baza/sql_queries/generic_update.rb
baza-0.0.34 lib/baza/sql_queries/generic_update.rb
baza-0.0.33 lib/baza/sql_queries/generic_update.rb
baza-0.0.32 lib/baza/sql_queries/generic_update.rb
baza-0.0.31 lib/baza/sql_queries/generic_update.rb
baza-0.0.30 lib/baza/sql_queries/generic_update.rb
baza-0.0.29 lib/baza/sql_queries/generic_update.rb
baza-0.0.28 lib/baza/sql_queries/generic_update.rb
baza-0.0.27 lib/baza/sql_queries/generic_update.rb
baza-0.0.26 lib/baza/sql_queries/generic_update.rb
baza-0.0.25 lib/baza/sql_queries/generic_update.rb
baza-0.0.24 lib/baza/sql_queries/generic_update.rb
baza-0.0.23 lib/baza/sql_queries/generic_update.rb
baza-0.0.22 lib/baza/sql_queries/generic_update.rb
baza-0.0.21 lib/baza/sql_queries/generic_update.rb