Sha256: 83ed1548d32c372725c6d28f7a41947f4dbb87bc6c0733509b7292850cbd7d1e

Contents?: true

Size: 891 Bytes

Versions: 1

Compression:

Stored size: 891 Bytes

Contents

module DatabaseFlusher
  module ActiveRecord
    class AbstractAdapter
      attr_reader :connection, :raw_connection

      def initialize(connection)
        @connection = connection
        @raw_connection = connection.raw_connection
      end

      def delete(*tables)
        disable_referential_integrity(*tables) do
          stmts = tables.map do |name|
            "DELETE FROM #{quote_table_name(name)}"
          end
          sql = stmts.join(';')
          execute_multi sql
        end
      end

      private

      def execute_multi(sql)
        connection.execute sql
      end

      def execute(sql)
        connection.execute sql
      end

      def quote_table_name(name)
        connection.quote_table_name(name)
      end

      def disable_referential_integrity(*tables, &block)
        connection.disable_referential_integrity(&block)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
database_flusher-0.2.0 lib/database_flusher/active_record/adapters/abstract_adapter.rb