Module: ActiveRecord::DatabaseComments::Adapters::MysqlAdapter

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_record/database_comments/adapters/mysql_adapter.rb

Instance Method Summary collapse

Instance Method Details

#columns_with_comment(table_name, name = nil) ⇒ Object

Returns an array of Column objects for the table specified by table_name.



59
60
61
62
63
64
65
66
# File 'lib/active_record/database_comments/adapters/mysql_adapter.rb', line 59

def columns_with_comment(table_name, name = nil)#:nodoc:
  sql = "SHOW FULL FIELDS FROM #{quote_table_name(table_name)}"
  execute_and_free(sql, 'SCHEMA') do |result|
    each_hash(result).map do |field|
      new_column_with_comment(field[:Field], field[:Default], field[:Type], field[:Null] == "YES", field[:Collation], field[:Comment])
    end
  end
end

#new_column_with_comment(field, default, type, null, collation, comment) ⇒ Object

def create_table_with_mysql_options(table_name, options = {}) #:nodoc:

  create_table_without_mysql_options(table_name, options.reverse_merge(options: options[:mysql_options] ? options[:mysql_options] : "ENGINE=InnoDB"))
end


42
43
44
# File 'lib/active_record/database_comments/adapters/mysql_adapter.rb', line 42

def new_column_with_comment(field, default, type, null, collation, comment) # :nodoc:
  "#{self.class.name}::Column".constantize.new(field, default, type, null, collation, comment)
end

#table_options(table_name) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_record/database_comments/adapters/mysql_adapter.rb', line 46

def table_options(table_name)
  sql = "SHOW TABLE STATUS "
  sql << "IN #{quote_table_name(current_database)} "
  sql << "LIKE #{quote(table_name)}"
  ohmy = execute_and_free(sql, 'SCHEMA') do |result|
    each_hash(result).map do |field|
      "ENGINE=#{field[:Engine]} COLLATE=#{field[:Collation]} COMMENT='#{field[:Comment]}'"
    end
  end
  ohmy.first
end