Sha256: fc581f8910701207ce7f2b75bbf15407f6afbdff01c96d781921830f3c168af8

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Motor
  module ActiveRecordUtils
    module_function

    def reset_id_sequence!(model)
      case ActiveRecord::Base.connection.class.name
      when 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
        ActiveRecord::Base.connection.reset_pk_sequence!(model.table_name)
      else
        ActiveRecord::Base.connection.reset_sequence!(model.table_name, 'id')
      end
    end

    def generate_csv_for_relation(relation, reset_limit: false)
      relation = relation.limit(nil).offset(nil) if reset_limit

      result = relation.klass.connection.exec_query(relation.to_sql)

      CSV.generate do |csv|
        csv << result.columns

        result.rows.each { |row| csv << row }
      end
    end
  end
end

require_relative './active_record_utils/types'
require_relative './active_record_utils/fetch_methods'
require_relative './active_record_utils/defined_scopes_extension'
require_relative './active_record_utils/active_storage_links_extension'
require_relative './active_record_utils/active_storage_blob_patch'
require_relative './active_record_utils/active_record_filter_patch'
require_relative './active_record_utils/active_record_connection_column_patch'
require_relative './active_record_utils/action_text_attribute_patch'
require_relative './active_record_utils/ar_lazy_preload_patch'

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
motor-admin-0.2.19 lib/motor/active_record_utils.rb
motor-admin-0.2.18 lib/motor/active_record_utils.rb
motor-admin-0.2.17 lib/motor/active_record_utils.rb
motor-admin-0.2.16 lib/motor/active_record_utils.rb
motor-admin-0.2.15 lib/motor/active_record_utils.rb
motor-admin-0.2.14 lib/motor/active_record_utils.rb