vantage6.algorithm.tools.decorators.database_connection#
- database_connection(types, include_metadata=True)#
Decorator that adds a database connection to a function
By adding @database_connection to a function, a database connection will be added to the front of the argument list. This connection can be used to communicate with the database.
- Parameters:
types (list[str]) – List of types of databases to connect to. Currently only “OMOP” is supported.
include_metadata (bool) – Whether to include metadata in the function arguments. This metadata contains the database name, CDM schema, and results schema. Default is True.
- Return type:
callable
Example
For a single OMOP data source: >>> @database_connection(types=[“OMOP”]) >>> def my_algorithm(connection: Connection, meta: OHDSIMetaData, >>> <other arguments>): >>> pass
In case you have multiple OMOP data sources: >>> @database_connection(types=[“OMOP”, “OMOP”]) >>> def my_algorithm(connection1: Connection, meta1: OHDSIMetaData, >>> connection2: Connection, meta2: OHDSIMetaData, >>> <other arguments>): >>> pass
In the case you do not want to include the metadata: >>> @database_connection(types=[“OMOP”], include_metadata=False) >>> def my_algorithm(connection: Connection, <other arguments>): >>> pass