glimr/db/db
Database Utilities
High-level database utilities for provider-based configuration and multi-database support.
NOTE: Pool management and transactions are now in driver packages:
- glimr_sqlite.start_pool(), glimr_sqlite.transaction()
- glimr_postgres.start_pool(), glimr_postgres.transaction()
Values
pub fn get_connection(
connections: List(driver.Connection),
name: String,
) -> driver.Connection
Finds a connection by name from a list of connections. Panics if the connection is not found.
pub fn get_connection_safe(
connections: List(driver.Connection),
name: String,
) -> Result(driver.Connection, Nil)
Finds a connection by name from a list of connections. Returns Error(Nil) if the connection is not found instead of panicking.
pub fn load_config() -> pool_connection.Config
Builds database configuration from environment variables. Reads DB_DRIVER and DB_POOL_SIZE from the environment.
For PostgreSQL, uses DB_URL if set, otherwise uses individual parameters: DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD.
For SQLite, DB_DATABASE is preferred but DB_PATH is supported for backward compatibility.
pub fn load_provider() -> List(driver.Connection)
Loads the database provider configuration by calling the
database_provider.register() function from the user’s
application. Returns a list of Connection configurations.
Panics if the database_provider module is not found or doesn’t have a register() function.