z_db_pool (zotonic_core v1.0.0-rc.17)
Database pool wrapper. Start and stop database pool workers.
Summary
Functions
Optionally add the db pool connection
Merge the database options from the global config into the site config. If the site uses the default database and it has no schema defined then the site's name is used as the schema name. If the site uses its own database then the schema defaults to "public".
Request a database connection worker from the database pool. Each worker manages a single database connection. If a worker is available then its pid is returned. The worker can then provide the actual database connection for querying the database. See z_db_pgql for query functions that fetch the database connection from the worker process.
Get all configuration options for this site which are related to the database configuration.
Request a database connection and unpause it if it was paused.
Ensure that all worker processes are paused. This is useful if a large update of the schema needs to be done.
Perform a connect to test if the database is working.
Tell all (paused) workers that it is ok to continue.
Functions
Optionally add the db pool connection
-spec database_options(atom(), proplists:proplist()) -> proplists:proplist().
Merge the database options from the global config into the site config. If the site uses the default database and it has no schema defined then the site's name is used as the schema name. If the site uses its own database then the schema defaults to "public".
-spec database_options(atom(), proplists:proplist(), proplists:proplist()) -> proplists:proplist().
Request a database connection worker from the database pool. Each worker manages a single database connection. If a worker is available then its pid is returned. The worker can then provide the actual database connection for querying the database. See z_db_pgql for query functions that fetch the database connection from the worker process.
-spec get_database_options(z:context()) -> proplists:proplist().
Get all configuration options for this site which are related to the database configuration.
-spec get_unpaused_connection(Context) -> {ok, pid()} | {error, full | nodatabase} when Context :: z:context().
Request a database connection and unpause it if it was paused.
-spec pause_connections(Context) -> ok when Context :: z:context().
Ensure that all worker processes are paused. This is useful if a large update of the schema needs to be done.
-spec test_connection(atom(), proplists:proplist()) -> ok | {error, nodatabase | noschema | term()}.
Perform a connect to test if the database is working.
Tell all (paused) workers that it is ok to continue.