Expand description
Database connections backed by the model config.
Besides the one-shot connect/connect_with_url helpers, this module
holds a process-global connection installed once at application boot
(init) and read from request handlers via pool. Controllers reach it
through Context::db().
Functions§
- connect
- Connects to the database named by the current environment’s
config/<env>.ymldatabase.url, honouring itslogger.sqltoggle and anydatabase.pool/database.connect_timeoutknobs. - connect_
with_ url - Connects using an explicit database URL, bypassing the config file. SQL statement logging stays enabled (the default).
- init
- Connects (via
connect) and installs the process-global pool, returning a reference to it. Idempotent: if already initialised, the existing connection is returned and the new one discarded. Call once at server boot. - pool
- Returns the global connection, panicking if
init/set_poolwas never called. Use from request handlers where boot is guaranteed to have run. - pool_
options - Builds
ConnectOptionswith SQL logging plus optional pool tuning:max_connections(configdatabase.pool) andconnect_timeoutin seconds (configdatabase.connect_timeout). - set_
pool - Installs an already-open connection as the global pool (e.g. in tests).
Returns
Errwith the connection back if one was already installed. - test_
lock - A process-global lock for serializing tests that share the global pool.
- try_
pool - Returns the global connection if installed, else
None.