cowbird.database ================ .. py:module:: cowbird.database .. autoapi-nested-parse:: Database package for pyramid. Add the database in the pyramid registry and a property db for the requests. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/cowbird/database/base/index /autoapi/cowbird/database/mongodb/index /autoapi/cowbird/database/stores/index Attributes ---------- .. autoapisummary:: cowbird.database.AnySettingsContainer cowbird.database.LOGGER Classes ------- .. autoapisummary:: cowbird.database.MongoDatabase Functions --------- .. autoapisummary:: cowbird.database.get_registry cowbird.database.get_settings cowbird.database.get_db cowbird.database.includeme Package Contents ---------------- .. py:class:: MongoDatabase(container: cowbird.typedefs.AnySettingsContainer) Bases: :py:obj:`cowbird.database.base.DatabaseInterface` Return the unique identifier of db type matching settings. Initialize the mongo database from various type of container. .. py:attribute:: _database :type: pymongo.database.Database :value: None .. py:attribute:: _settings :type: cowbird.typedefs.SettingsType :value: None .. py:attribute:: _stores :type: Dict[str, AnyMongodbStore] :value: None .. py:attribute:: type :value: 'mongodb' .. py:method:: reset_store(store_type: AnyMongodbStoreType) -> Optional[AnyMongodbStore] .. py:method:: get_store(store_type: Union[str, Type[cowbird.database.stores.StoreInterface], AnyMongodbStoreType], *store_args: Any, **store_kwargs: Any) -> AnyMongodbStore Retrieve a store from the database. :param store_type: type of the store to retrieve/create. :param store_args: additional arguments to pass down to the store. :param store_kwargs: additional keyword arguments to pass down to the store. .. py:method:: get_session() -> Any .. py:method:: get_information() -> cowbird.typedefs.JSON :returns: {'version': version, 'type': db_type} .. py:method:: is_ready() -> bool .. py:data:: AnySettingsContainer .. py:function:: get_registry(container: cowbird.typedefs.AnyRegistryContainer, nothrow: bool = False) -> Optional[pyramid.registry.Registry] Retrieves the application ``registry`` from various containers referencing to it. .. py:function:: get_settings(container: Optional[cowbird.typedefs.AnySettingsContainer], app: bool = False) -> cowbird.typedefs.SettingsType Retrieve application settings from a supported container. :param container: supported container with a handle to application settings. :param app: allow retrieving from current thread registry if no container was defined. :returns: found application settings dictionary. :raise TypeError: when no application settings could be found or unsupported container. .. py:data:: LOGGER .. py:function:: get_db(container: cowbird.typedefs.AnySettingsContainer, reset_connection: bool = False) -> mongodb.MongoDatabase Obtains the database connection from configured application settings. If :paramref:`reset_connection` is ``True``, the :paramref:`container` must be the application :class:`Registry` or any container that can retrieve it to accomplish reference reset. Otherwise, any settings container can be provided. .. py:function:: includeme(config: pyramid.config.Configurator) -> None