R6 Class for managing database operations related to survey data storage
and retrieval using PostgreSQL. Includes automatic tracking of creation date,
update date, session ID, and IP address.
Details
This class handles all database interactions for survey data, including:
Table creation and modification with tracking columns
Data insertion with automatic timestamp management
Session and IP tracking
Transaction management
Error handling and logging
Tracking columns automatically added to each table:
date_created: Timestamp when record was created
date_updated: Timestamp when record was last updated
session_id: Shiny session identifier
ip_address: Client IP address
Public fields
session_id
Unique identifier for the current session
pool
Database connection pool
logger
Logger instance for tracking operations
Methods
Method new()
Create a new Database Operations instance
Usage
db_ops$new(pool, session_id, logger)
Arguments
pool
Pool object. Database connection pool
session_id
Character. Unique identifier for the current session
logger
survey_logger object. Logger instance for tracking operations
Method operate()
Execute a database operation with transaction handling
Usage
db_ops$operate(operation, error_message)
Arguments
operation
Function. The database operation to execute
error_message
Character. Message to display if operation fails
Returns
Result of the operation or error message if failed
Method ensure_tracking_columns()
Ensure tracking columns exist in a table
Usage
db_ops$ensure_tracking_columns(table_name)
Arguments
table_name
Character. Name of the table to check/modify
Method create_survey_table()
Create new survey data table with tracking columns
Usage
db_ops$create_survey_table(write_table, data)
Arguments
write_table
Character. Name of the table to create
data
data.frame. Data frame containing the schema for the new table
Returns
Character. The sanitized table name
Update existing survey table with new data
Method update_survey_table()
Usage
db_ops$update_survey_table(write_table, data)
Arguments
write_table
Character. Name of the table to update
data
data.frame. Data frame containing the new data
Returns
Character. The sanitized table name
Method clone()
The objects of this class are cloneable with this method.
Usage
db_ops$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.