Sha256: 21e8e389435b6041ec3fa5f42f026b95ee622c938655de7112b0a173375cca89

Contents?: true

Size: 930 Bytes

Versions: 4

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  module Dbt
    module Model
      module Staging
        class Sql
          include ActiveRecord::Dbt::Model::Staging::Base

          attr_reader :table_name

          def export_path
            "#{basename}.sql"
          end

          def select_column_names
            columns_group_by_column_type.sort_by do |key, _|
              SORT_COLUMN_TYPES.index(key)
            end.to_h
          end

          private

          def columns
            ActiveRecord::Base.connection.columns(table_name)
          end

          def columns_group_by_column_type
            columns.group_by do |column|
              if id?(column.name)
                'ids'
              elsif enum?(column.name)
                'enums'
              else
                column.type.to_s.pluralize
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activerecord-dbt-0.4.0 lib/active_record/dbt/model/staging/sql.rb
activerecord-dbt-0.3.0 lib/active_record/dbt/model/staging/sql.rb
activerecord-dbt-0.2.0 lib/active_record/dbt/model/staging/sql.rb
activerecord-dbt-0.1.0 lib/active_record/dbt/model/staging/sql.rb