Database Operations Class
db_ops.RdR6 Class for managing database operations related to survey data storage and retrieval using MySQL and other DBI-compatible databases.
Details
This class handles all database interactions for survey data, including:
- Table creation and modification 
- Data insertion and retrieval 
- Transaction management 
- Error handling and logging 
Methods
Method operate()
Execute a database operation with transaction handling using connection pool
Method create_survey_table()
Check pre-defined survey table for required columns
Arguments
- write_table
- Character. Name of the pre-defined table to check 
- data
- data.frame. Data frame containing the required columns for the survey 
- survey_obj
- Survey.JS definition object that contains the complete survey structure. A nested list containing: - pages
- List of survey pages 
- elements
- List of survey questions/elements, where each element contains: 
- name
- Question identifier 
- type
- Question type (e.g., "checkbox", "text", "radio") 
- showOtherItem
- Logical. Whether the question has an "other" option 
 - Used to determine column types and handle special question features like "other" options. Default: NULL 
Method update_survey_table()
Method read_table()
Read data from a survey table with optional filtering
Usage
db_ops$read_table(
  table_name,
  columns = NULL,
  filters = NULL,
  order_by = NULL,
  desc = FALSE,
  limit = NULL,
  update_last_sql = TRUE
)Arguments
- table_name
- Character. Name of the table to read from 
- columns
- Character vector. Specific columns to read (NULL for all columns) 
- filters
- List. Named list of filter conditions (e.g., list(status = "active")) 
- order_by
- Character vector. Columns to order by 
- desc
- Logical. If TRUE, sort in descending order 
- limit
- Numeric. Maximum number of rows to return (NULL for all rows) 
- update_last_sql
- Logical. If TRUE, update logger's last_sql_statement (default: TRUE) 
Method update_by_id()
Update specific columns in a table for a given row ID
Method perform_survey_update()
Perform survey update operation using join columns
Method get_required_columns()
Get required columns for a survey to help with pre-defined table setup