Sha256: 351f642eb292196f93400d949d7ff2584963632da9969f8403c4e59f47669176

Contents?: true

Size: 763 Bytes

Versions: 2

Compression:

Stored size: 763 Bytes

Contents

class Upsert
  class ColumnDefinition
    # @private
    class Mysql < ColumnDefinition
      class << self
        def all(connection, table_name)
          connection.execute("SHOW COLUMNS FROM #{connection.quote_ident(table_name)}").map do |row|
            # {"Field"=>"name", "Type"=>"varchar(255)", "Null"=>"NO", "Key"=>"PRI", "Default"=>nil, "Extra"=>""}
            name = row['Field'] || row['COLUMN_NAME']
            type = row['Type'] || row['COLUMN_TYPE']
            default = row['Default'] || row['COLUMN_DEFAULT']
            new connection, name, type, default
          end.sort_by do |cd|
            cd.name
          end
        end
      end
      
      def equality(left, right)
        "#{left} <=> #{right}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
upsert-2.0.3 lib/upsert/column_definition/mysql.rb
upsert-2.0.2 lib/upsert/column_definition/mysql.rb