Module: Dbviewer::DatabaseHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/dbviewer/database_helper.rb
Instance Method Summary collapse
-
#column_type_from_info(column_name, columns) ⇒ Object
Extract column type from columns info.
-
#column_type_icon(column_type) ⇒ Object
Get appropriate icon for column data type.
-
#current_table?(table_name) ⇒ Boolean
Determine if the current table should be active in the sidebar.
-
#format_table_name(table_name) ⇒ Object
Format table name for display - truncate if too long.
-
#get_database_manager ⇒ Object
Helper to access the database manager.
-
#has_timestamp_column?(table_name) ⇒ Boolean
Check if a table has a created_at column.
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 |
#column_type_icon(column_type) ⇒ Object
Get appropriate icon for column data type
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/dbviewer/database_helper.rb', line 26 def column_type_icon(column_type) case column_type.to_s.downcase when /int/, /serial/, /number/, /decimal/, /float/, /double/ "bi-123" when /char/, /text/, /string/, /uuid/ "bi-fonts" when /date/, /time/ "bi-calendar" when /bool/ "bi-toggle-on" when /json/, /jsonb/ "bi-braces" when /array/ "bi-list-ol" else "bi-file-earmark" end end |
#current_table?(table_name) ⇒ Boolean
Determine if the current table should be active in the sidebar
46 47 48 |
# File 'app/helpers/dbviewer/database_helper.rb', line 46 def current_table?(table_name) @table_name.present? && @table_name == table_name end |
#format_table_name(table_name) ⇒ Object
Format table name for display - truncate if too long
51 52 53 54 55 56 57 |
# File 'app/helpers/dbviewer/database_helper.rb', line 51 def format_table_name(table_name) if table_name.length > 20 "#{table_name.first(17)}..." else table_name end end |
#get_database_manager ⇒ Object
Helper to access the database manager
13 14 15 |
# File 'app/helpers/dbviewer/database_helper.rb', line 13 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
4 5 6 7 8 9 10 |
# File 'app/helpers/dbviewer/database_helper.rb', line 4 def (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 |