cowbird.database
Database package for pyramid.
Add the database in the pyramid registry and a property db for the requests.
Submodules
Attributes
Classes
Return the unique identifier of db type matching settings. |
Functions
|
Retrieves the application |
|
Retrieve application settings from a supported container. |
|
Obtains the database connection from configured application settings. |
|
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'
- 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.
- 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.get_db(container: cowbird.typedefs.AnySettingsContainer, reset_connection: bool = False) mongodb.MongoDatabase [source]
Obtains the database connection from configured application settings.
If
reset_connection
isTrue
, thecontainer
must be the applicationRegistry
or any container that can retrieve it to accomplish reference reset. Otherwise, any settings container can be provided.