Overarching Goal:
- Create an ojo_connect function that can either be used invisibly as the default argument to the db connection argument of ojo_tbl or ojo_query, OR be used with no side-effects to create a connection object that can be passed around manually
- Connect by default to our Postgres db but alternatively to other backends like duckdb
- Integrate with ojo_auth for auth related config values
- Be able to create a connection pool for when used programatically in an environment like R Shiny or highly parallel code with transactions
Currently, ojo_connect:
- Creates a connection type string (ojo_pool or ojo_con) based on arguments
- Creates a connection key using connection type and the DBI driver name passed to the .driver arg, e.g. RPostgres
- Creates a connection args variable which is a list of connection arguments
- Switches list depending on the backend
- Aborts if driver is an unsupported one
- Programatically passes the args list to the appropriate connection function using rlang::exec and !!!
- Assigns the connection object to a variable named after the connection key in the environment specified by the .env argument, defaulting to the global environment
- If the driver is duckdb:
- Installs needed plugins like httpfs and sets s3_endpoints to google cloud storage
- Launches a withr deferred statement in the environment where the connection was created that closes the connection when that environment shuts down
It tries to, but doesn't succeed in:
- Distinguishing between admin and default accounts, limiting access type or impersonating roles as needed
- Allowing for local, side-effect free assignment of connection object with no deferred connection closing
It needs to:
- Achieve overarching goals
- Be highly modular and future-proofed for new backends
- Use the implementation of ojo_auth in the ojodb-v3 and connect branches
It maybe shouldn't:
- Try to do too many things without breaking into sub functions
It maybe could:
- Have breaking changes to clean up function signature
- Use classed list arguments whose values are provided using a function of the same name as the argument
- Like ojo_auth does with db_config = db_config(...) or bslib does with navbar_options = navbar_options(...)
Overarching Goal:
Currently,
ojo_connect:It tries to, but doesn't succeed in:
It needs to:
It maybe shouldn't:
It maybe could: