Sha256: 1cc29a23669b1990f1dfdb599d292e1563ce73fb4788f54f74a48b02a9186e33

Contents?: true

Size: 869 Bytes

Versions: 6

Compression:

Stored size: 869 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'] || row[:Field] || row[:COLUMN_NAME]
            type = row['Type'] || row['COLUMN_TYPE'] || row[:Type] || row[:COLUMN_TYPE]
            default = row['Default'] || row['COLUMN_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

6 entries across 6 versions & 1 rubygems

Version Path
upsert-2.2.1 lib/upsert/column_definition/mysql.rb
upsert-2.2.0 lib/upsert/column_definition/mysql.rb
upsert-2.1.2 lib/upsert/column_definition/mysql.rb
upsert-2.1.1 lib/upsert/column_definition/mysql.rb
upsert-2.1.0 lib/upsert/column_definition/mysql.rb
upsert-2.0.4 lib/upsert/column_definition/mysql.rb