Sha256: 4accf56d70add89f1e5816ee507575e7d4ca1663bdae2ff56244cc6c84e3ecc5

Contents?: true

Size: 921 Bytes

Versions: 8

Compression:

Stored size: 921 Bytes

Contents

# frozen_string_literal: true
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

8 entries across 8 versions & 1 rubygems

Version Path
database_flusher-0.3.4 lib/database_flusher/active_record/adapters/abstract_adapter.rb
database_flusher-0.3.3 lib/database_flusher/active_record/adapters/abstract_adapter.rb
database_flusher-0.3.2 lib/database_flusher/active_record/adapters/abstract_adapter.rb
database_flusher-0.3.1 lib/database_flusher/active_record/adapters/abstract_adapter.rb
database_flusher-0.3.0 lib/database_flusher/active_record/adapters/abstract_adapter.rb
database_flusher-0.2.3 lib/database_flusher/active_record/adapters/abstract_adapter.rb
database_flusher-0.2.2 lib/database_flusher/active_record/adapters/abstract_adapter.rb
database_flusher-0.2.1 lib/database_flusher/active_record/adapters/abstract_adapter.rb