Sha256: 4d6734239061283fa73cdbef1e883654b63cc2ab314bc39d2f174d735afdacf0

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

class Upsert
  class Buffer
    # @private
    class SQLite3_Database < Buffer
      include Quoter

      def chunk
        return false if rows.empty?
        row = rows.shift
        %{
          INSERT OR IGNORE INTO "#{table_name}" (#{row.columns_sql}) VALUES (#{row.values_sql});
          UPDATE "#{table_name}" SET #{row.set_sql} WHERE #{row.where_sql}
        }
      end

      def execute(sql)
        connection.execute_batch sql
      end

      def quote_string(v)
        SINGLE_QUOTE + SQLite3::Database.quote(v) + SINGLE_QUOTE
      end

      def quote_binary(v)
        X_AND_SINGLE_QUOTE + v.unpack("H*")[0] + SINGLE_QUOTE
      end

      def quote_time(v)
        quote_string [v.strftime(ISO8601_DATETIME), sprintf(USEC_SPRINTF, v.usec)].join('.')
      end
      
      def quote_ident(k)
        DOUBLE_QUOTE + SQLite3::Database.quote(k.to_s) + DOUBLE_QUOTE
      end

      def quote_boolean(v)
        s = v ? 't' : 'f'
        quote_string s
      end

      def quote_big_decimal(v)
        v.to_f
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
upsert-0.1.0 lib/upsert/buffer/sqlite3_database.rb