Sha256: 8e9e240318e49c5adaa08dcb59a4b0908ff691e93838f122b22f317f06b33421

Contents?: true

Size: 899 Bytes

Versions: 1

Compression:

Stored size: 899 Bytes

Contents

class Upsert
  class ColumnDefinition
    # @private
    class Mysql2_Client < ColumnDefinition
      class << self
        def all(connection, table_name)
          connection.execute("SHOW COLUMNS FROM #{connection.quote_ident(table_name)}").map do |row|
            name, type, default = if row.is_a?(Array)
              # you don't know if mysql2 is going to give you an array or a hash... and you shouldn't specify, because it's sticky
              # ["name", "varchar(255)", "YES", "UNI", nil, ""]
              row.values_at(0,1,4)
            else
              # {"Field"=>"name", "Type"=>"varchar(255)", "Null"=>"NO", "Key"=>"PRI", "Default"=>nil, "Extra"=>""}
              [row['Field'], row['Type'], row['Default']]
            end
            new connection, name, type, default
          end.sort_by do |cd|
            cd.name
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
upsert-1.0.2 lib/upsert/column_definition/Mysql2_Client.rb