Class: DbdocEngine::DbDesignTableGroupQueries
- Inherits:
-
Object
- Object
- DbdocEngine::DbDesignTableGroupQueries
- Defined in:
- app/queries/dbdoc_engine/db_design_table_group_queries.rb
Constant Summary collapse
- TABLE_INCLUDES =
Eager loading configuration for tables and columns associations
{ db_design_dynamic_tables: :db_design_dynamic_columns }.freeze
Class Method Summary collapse
-
.all_groups_for_selection ⇒ ActiveRecord::Relation
Get all groups for selection dropdowns.
-
.all_groups_with_tables_and_columns ⇒ ActiveRecord::Relation
Fetch all table groups with their associated tables and columns.
-
.count_all_groups ⇒ Integer
Count all active (non-deleted) table groups.
-
.create_table_group(params) ⇒ DbDesignTableGroup
Create a new table group.
-
.find_group_name(group_id) ⇒ String?
Find group name by ID.
-
.find_group_with_tables(group_id) ⇒ DbDesignTableGroup
Find group with associated tables.
-
.find_group_with_tables_and_columns(id) ⇒ DbDesignTableGroup?
Find a specific group by ID with preloaded tables and columns.
-
.find_with_deleted(id) ⇒ DbDesignTableGroup
Find a group including soft-deleted records.
-
.group_exists?(group_name) ⇒ Boolean
Check if a group name exists in active records.
-
.group_names_except(excluded_id) ⇒ Array<String>
Get group names excluding a specific entry.
- .groups_with_tables_having_columns ⇒ Object
-
.model ⇒ Class
Centralized model reference for table groups.
-
.permanent_delete(table_group) ⇒ Boolean
Permanently delete a group.
-
.restore(table_group) ⇒ Boolean
Restore a soft-deleted group.
-
.search_all_groups(search_term = nil, include_deleted = false) ⇒ ActiveRecord::Relation
Unified search across groups with optional deleted records.
-
.search_deleted_groups(search_term = nil) ⇒ ActiveRecord::Relation
Search specifically in soft-deleted groups.
-
.select_all_groups ⇒ ActiveRecord::Relation
Retrieve lightweight group data for selection lists.
-
.soft_delete(table_group) ⇒ Boolean
Soft delete a table group.
-
.update_table_group(table_group, params) ⇒ Boolean
Update existing table group.
Class Method Details
.all_groups_for_selection ⇒ ActiveRecord::Relation
Get all groups for selection dropdowns
124 125 126 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 124 def all_groups_for_selection model.select(:id, :group_name).order(:group_name) end |
.all_groups_with_tables_and_columns ⇒ ActiveRecord::Relation
Fetch all table groups with their associated tables and columns
18 19 20 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 18 def all_groups_with_tables_and_columns model.includes(TABLE_INCLUDES).all end |
.count_all_groups ⇒ Integer
Count all active (non-deleted) table groups
31 32 33 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 31 def count_all_groups model.count end |
.create_table_group(params) ⇒ DbDesignTableGroup
Create a new table group
89 90 91 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 89 def create_table_group(params) model.new(params).tap(&:save) end |
.find_group_name(group_id) ⇒ String?
Find group name by ID
75 76 77 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 75 def find_group_name(group_id) model.find_by(id: group_id)&.group_name end |
.find_group_with_tables(group_id) ⇒ DbDesignTableGroup
Find group with associated tables
131 132 133 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 131 def find_group_with_tables(group_id) model.includes(:db_design_dynamic_tables).find(group_id) end |
.find_group_with_tables_and_columns(id) ⇒ DbDesignTableGroup?
Find a specific group by ID with preloaded tables and columns
25 26 27 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 25 def find_group_with_tables_and_columns(id) model.includes(TABLE_INCLUDES).find_by(id: id) end |
.find_with_deleted(id) ⇒ DbDesignTableGroup
Find a group including soft-deleted records
44 45 46 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 44 def find_with_deleted(id) model.with_deleted.find(id) end |
.group_exists?(group_name) ⇒ Boolean
Check if a group name exists in active records
82 83 84 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 82 def group_exists?(group_name) model.without_deleted.where(group_name: group_name).exists? end |
.group_names_except(excluded_id) ⇒ Array<String>
Get group names excluding a specific entry
68 69 70 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 68 def group_names_except(excluded_id) model.where.not(id: excluded_id).pluck(:group_name) end |
.groups_with_tables_having_columns ⇒ Object
135 136 137 138 139 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 135 def groups_with_tables_having_columns model.includes(db_design_dynamic_tables: :db_design_dynamic_columns) .references(:db_design_dynamic_tables) .where(db_design_dynamic_tables: { deleted_at: nil }) end |
.model ⇒ Class
Centralized model reference for table groups
12 13 14 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 12 def model DbDesignTableGroup end |
.permanent_delete(table_group) ⇒ Boolean
Permanently delete a group
118 119 120 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 118 def permanent_delete(table_group) table_group.destroy end |
.restore(table_group) ⇒ Boolean
Restore a soft-deleted group
111 112 113 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 111 def restore(table_group) table_group.restore end |
.search_all_groups(search_term = nil, include_deleted = false) ⇒ ActiveRecord::Relation
Unified search across groups with optional deleted records
52 53 54 55 56 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 52 def search_all_groups(search_term = nil, include_deleted = false) query = include_deleted ? model.with_deleted : model.all query = apply_search_scope(query, search_term) query.order(Arel.sql("LOWER(group_name) ASC")) # Add ordering here end |
.search_deleted_groups(search_term = nil) ⇒ ActiveRecord::Relation
Search specifically in soft-deleted groups
61 62 63 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 61 def search_deleted_groups(search_term = nil) apply_search_scope(model.only_deleted, search_term) end |
.select_all_groups ⇒ ActiveRecord::Relation
Retrieve lightweight group data for selection lists
37 38 39 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 37 def select_all_groups model.select(:id, :group_name) end |
.soft_delete(table_group) ⇒ Boolean
Soft delete a table group
104 105 106 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 104 def soft_delete(table_group) table_group.soft_delete end |
.update_table_group(table_group, params) ⇒ Boolean
Update existing table group
97 98 99 |
# File 'app/queries/dbdoc_engine/db_design_table_group_queries.rb', line 97 def update_table_group(table_group, params) table_group.update(params) end |