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

child_spec(Site, SiteProps)

Optionally add the db pool connection

close_connections()

close_connections(Context)

database_options(Sitename, SiteProps)

-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".

database_options(Sitename, SiteProps, GlobalProps)

-spec database_options(atom(), proplists:proplist(), proplists:proplist()) -> proplists:proplist().

db_driver(SiteProps)

db_driver_default()

db_pool_name(Site)

get_connection(Context)

-spec get_connection(z:context()) -> {ok, pid()} | {error, full | nodatabase}.

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_database_options(Context)

-spec get_database_options(z:context()) -> proplists:proplist().

Get all configuration options for this site which are related to the database configuration.

get_unpaused_connection(Context)

-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.

pause_connections(Context)

-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.

return_connection(Worker, Context)

-spec return_connection(pid(), z:context()) -> ok | {error, term()}.

status()

status(Context)

test_connection(Context)

-spec test_connection(z:context()) -> ok | {error, nodatabase | noschema | term()}.

test_connection(Site, SiteProps)

-spec test_connection(atom(), proplists:proplist()) -> ok | {error, nodatabase | noschema | term()}.

Perform a connect to test if the database is working.

unpause_connections(Context)

Tell all (paused) workers that it is ok to continue.