Sha256: 1c0066c7da04f3a1d21ff588936d627fc9beb88e38eef1acbb6e3ff6cf97dec9
Contents?: true
Size: 1.23 KB
Versions: 5
Compression:
Stored size: 1.23 KB
Contents
module DatabaseDocumenter class DatabaseComment::PostgresDatabaseComment < DatabaseComment::BaseDatabaseComment def self.read_columns_comment(table_name) select_comment = <<-SQL SELECT cols.column_name, ( SELECT pg_catalog.col_description(c.oid, cols.ordinal_position::int) FROM pg_catalog.pg_class c WHERE c.oid = (SELECT ('"' || cols.table_name || '"')::regclass::oid) AND c.relname = cols.table_name ) AS column_comment FROM information_schema.columns cols WHERE cols.table_catalog = '#{database_name}' AND cols.table_name = '#{table_name}' AND cols.table_schema = 'public'; SQL columns_comment_hash = {} ActiveRecord::Base.connection.execute(select_comment).map { |c| columns_comment_hash[c['column_name']] = c['column_comment'] } columns_comment_hash end def self.read_table_comment(table_name) select_comment = <<-SQL select obj_description('public.#{table_name}'::regclass); SQL ActiveRecord::Base.connection.execute(select_comment)[0]['obj_description'] end end end
Version data entries
5 entries across 5 versions & 1 rubygems