Module: Dbviewer::DatabaseHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/dbviewer/database_helper.rb

Instance Method Summary collapse

Instance Method Details

#column_type_from_info(column_name, columns) ⇒ Object

Extract column type from columns info



18
19
20
21
22
23
# File 'app/helpers/dbviewer/database_helper.rb', line 18

def column_type_from_info(column_name, columns)
  return nil unless columns.present?

  column_info = columns.find { |c| c[:name].to_s == column_name.to_s }
  column_info ? column_info[:type].to_s.downcase : nil
end

#get_database_managerObject

Helper to access the database manager



4
5
6
# File 'app/helpers/dbviewer/database_helper.rb', line 4

def get_database_manager
  @database_manager ||= ::Dbviewer::Database::Manager.new
end

#has_timestamp_column?(table_name) ⇒ Boolean

Check if a table has a created_at column

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'app/helpers/dbviewer/database_helper.rb', line 9

def has_timestamp_column?(table_name)
  return false unless table_name.present?

  # Get the columns for the table directly using DatabaseManager
  columns = get_database_manager.table_columns(table_name)
  columns.any? { |col| col[:name] == "created_at" && [ :datetime, :timestamp ].include?(col[:type]) }
end