Sha256: 60b00132976789b6e73f10ef99658615c48d20d89c1f84d89686b2196ac99021

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

class Upsert
  # @private
  class Buffer
    class << self
      def for(connection, table_name)
        if connection.respond_to?(:raw_connection)
          # deal with ActiveRecord::Base.connection or ActiveRecord::Base.connection_pool.checkout
          connection = connection.raw_connection
        end
        const_get(connection.class.name.gsub(/\W+/, '_')).new connection, table_name
      end
    end

    SINGLE_QUOTE = %{'}
    DOUBLE_QUOTE = %{"}
    BACKTICK = %{`}
    E_AND_SINGLE_QUOTE = %{E'}
    X_AND_SINGLE_QUOTE = %{x'}
    USEC_SPRINTF = '%06d'
    ISO8601_DATETIME = '%Y-%m-%d %H:%M:%S' #FIXME ignores timezones i think

    attr_reader :connection
    attr_reader :table_name
    attr_reader :rows
    attr_writer :async
    
    def initialize(connection, table_name)
      @connection = connection
      @table_name = table_name
      @rows = []
    end

    def async?
      !!@async
    end

    def add(selector, document)
      rows << Row.new(self, selector, document)
      if sql = chunk
        execute sql
      end
    end

    def clear
      while sql = chunk
        execute sql
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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