Setup Global Survey Environment and Database Connection
survey_setup.Rd
Setup the global survey environment by creating database connections, environment variables, and a future asynchronous processing plan. The function:
Validates database configuration parameters
Sets required environment variables if not already present
Configures optional Shiny settings
Establishes a global database connection pool
Sets up asynchronous processing using future package with OS-specific configuration
Arguments
- db_config
A list containing database configuration parameters:
host: Database host address
port: Database port number
db_name: Name of the database
user: Database username
password: Database password
write_table: Name of the table for write operations
- shiny_config
Optional list of Shiny configuration parameters to be passed to configure_shiny function. If provided, these settings will be applied before database initialization.
- workers
Number of workers for parallel processing. Default is 3.
Value
Invisibly returns the database pool object. The pool is also assigned to 'app_pool' in the global environment.
Invisibly returns the initialized database pool object
Details
The function performs several initialization steps:
Validates the write_table parameter is a non-empty string
Checks for required database configuration fields
Sets environment variables (HOST, PORT, DB_NAME, USER, PASSWORD) if not present
Applies optional Shiny configuration
Creates a global database connection pool if it doesn't exist
Initializes future package for asynchronous operations based on OS
Environment variables are only set if they don't already exist, preserving any existing configurations.