wuttjamaican.db.conf

WuttJamaican - database configuration

wuttjamaican.db.conf.get_engines(config, prefix)[source]

Construct and return all database engines defined for a given config prefix.

For instance if you have a config file with:

[wutta.db]
keys = default, host
default.url = sqlite:///tmp/default.sqlite
host.url = sqlite:///tmp/host.sqlite

And then you call this function to get those DB engines:

get_engines(config, 'wutta.db')

The result of that will be like:

{'default': Engine(bind='sqlite:///tmp/default.sqlite'),
 'host': Engine(bind='sqlite:///tmp/host.sqlite')}
Parameters:
  • config – App config object.

  • prefix – Prefix for the config “section” which contains DB connection info.

Returns:

A dictionary of SQLAlchemy engines, with keys matching those found in config.

wuttjamaican.db.conf.get_setting(session, name)[source]

Get a setting value from the DB.

Note that this assumes (for now?) the DB contains a table named setting with (name, value) columns.

Parameters:
  • session – App DB session.

  • name – Name of the setting to get.

Returns:

Setting value as string, or None.

wuttjamaican.db.conf.make_engine_from_config(config_dict, prefix='sqlalchemy.', **kwargs)[source]

Construct a new DB engine from configuration dict.

This is a wrapper around upstream sqlalchemy.engine_from_config(). For even broader context of the SQLAlchemy Engine and their configuration, see Engine Configuration.

The purpose of the customization is to allow certain attributes of the engine to be driven by config, whereas the upstream function is more limited in that regard. The following in particular:

  • poolclass

  • pool_pre_ping

If these options are present in the configuration dict, they will be coerced to appropriate Python equivalents and then passed as kwargs to the upstream function.

An example config file leveraging this feature:

[wutta.db]
default.url = sqlite:///tmp/default.sqlite
default.poolclass = sqlalchemy.pool:NullPool
default.pool_pre_ping = true

Note that if present, the poolclass value must be a “spec” string, as required by load_object().