cowbird.database

Database package for pyramid.

Add the database in the pyramid registry and a property db for the requests.

Submodules

Attributes

AnySettingsContainer

LOGGER

Classes

MongoDatabase

Return the unique identifier of db type matching settings.

Functions

get_registry(→ Optional[pyramid.registry.Registry])

Retrieves the application registry from various containers referencing to it.

get_settings(→ cowbird.typedefs.SettingsType)

Retrieve application settings from a supported container.

get_db(→ mongodb.MongoDatabase)

Obtains the database connection from configured application settings.

includeme(→ None)

Package Contents

class cowbird.database.MongoDatabase(container: cowbird.typedefs.AnySettingsContainer)[source]

Bases: cowbird.database.base.DatabaseInterface

Return the unique identifier of db type matching settings.

Initialize the mongo database from various type of container.

_database: pymongo.database.Database = None
_settings: cowbird.typedefs.SettingsType = None
_stores: Dict[str, AnyMongodbStore] = None
type = 'mongodb'
reset_store(store_type: AnyMongodbStoreType) AnyMongodbStore | None[source]
get_store(store_type: str | Type[cowbird.database.stores.StoreInterface] | AnyMongodbStoreType, *store_args: Any, **store_kwargs: Any) AnyMongodbStore[source]

Retrieve a store from the database.

Parameters:
  • store_type – type of the store to retrieve/create.

  • store_args – additional arguments to pass down to the store.

  • store_kwargs – additional keyword arguments to pass down to the store.

get_session() Any[source]
get_information() cowbird.typedefs.JSON[source]
Returns:

{‘version’: version, ‘type’: db_type}

is_ready() bool[source]
cowbird.database.AnySettingsContainer[source]
cowbird.database.get_registry(container: cowbird.typedefs.AnyRegistryContainer, nothrow: bool = False) pyramid.registry.Registry | None[source]

Retrieves the application registry from various containers referencing to it.

cowbird.database.get_settings(container: cowbird.typedefs.AnySettingsContainer | None, app: bool = False) cowbird.typedefs.SettingsType[source]

Retrieve application settings from a supported container.

Parameters:
  • container – supported container with a handle to application settings.

  • app – allow retrieving from current thread registry if no container was defined.

Returns:

found application settings dictionary.

Raises:

TypeError – when no application settings could be found or unsupported container.

cowbird.database.LOGGER[source]
cowbird.database.get_db(container: cowbird.typedefs.AnySettingsContainer, reset_connection: bool = False) mongodb.MongoDatabase[source]

Obtains the database connection from configured application settings.

If reset_connection is True, the container must be the application Registry or any container that can retrieve it to accomplish reference reset. Otherwise, any settings container can be provided.

cowbird.database.includeme(config: pyramid.config.Configurator) None[source]