Sha256: 98135ec36baf00abd99e0d03342558b39e16b82b6dd5667a083e65785890277a

Contents?: true

Size: 854 Bytes

Versions: 5

Compression:

Stored size: 854 Bytes

Contents

module DatabaseDocumenter
  class DatabaseComment::MysqlDatabaseComment < DatabaseComment::BaseDatabaseComment
    def self.read_columns_comment(table_name)
      select_comment = <<-SQL
        SELECT `column_name`, `column_comment`
        FROM `information_schema`.`COLUMNS`
        WHERE `table_name` = '#{table_name}'
        AND `table_schema` = '#{database_name}'
        AND `column_comment` != '';
      SQL

      ActiveRecord::Base.connection.execute(select_comment).to_h
    end

    def self.read_table_comment(table_name)
      select_comment = <<-SQL
        SELECT `TABLE_COMMENT`
        FROM `information_schema`.`TABLES`
        WHERE `TABLE_NAME` = '#{table_name}'
        AND `table_schema` = '#{database_name}';
      SQL

      ActiveRecord::Base.connection.execute(select_comment).to_a.try('[]', 0).try('[]', 0)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
database_documenter-0.1.11 lib/database_documenter/database_comment/mysql_database_comment.rb
database_documenter-0.1.10 lib/database_documenter/database_comment/mysql_database_comment.rb
database_documenter-0.1.9 lib/database_documenter/database_comment/mysql_database_comment.rb
database_documenter-0.1.8 lib/database_documenter/database_comment/mysql_database_comment.rb
database_documenter-0.1.7 lib/database_documenter/database_comment/mysql_database_comment.rb