> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# dependencies

# `prefect.server.database.dependencies`

Injected database interface dependencies

## Functions

### `provide_database_interface` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L68](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L68)</sup>

```python theme={null}
provide_database_interface() -> PrefectDBInterface
```

Get the current Prefect REST API database interface.

If components of the interface are not set, defaults will be inferred
based on the dialect of the connection URL.

### `inject_db` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L142](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L142)</sup>

```python theme={null}
inject_db(fn: Callable[P, R]) -> Callable[P, R]
```

Decorator that provides a database interface to a function.

The decorated function *must* take a `db` kwarg and if a db is passed
when called it will be used instead of creating a new one.

### `db_injector` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L177](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L177)</sup>

```python theme={null}
db_injector(func: Union[_DBMethod[T, P, R], _DBFunction[P, R]]) -> Union[_Method[T, P, R], _Function[P, R]]
```

Decorator to inject a PrefectDBInterface instance as the first positional
argument to the decorated function.

Unlike `inject_db`, which injects the database connection as a keyword
argument, `db_injector` adds it explicitly as the first positional
argument. This change enhances type hinting by making the dependency on
PrefectDBInterface explicit in the function signature.

When decorating a coroutine function, the result will continue to pass the
iscoroutinefunction() test.

**Args:**

* `func`: The function or method to decorate.

**Returns:**

* A wrapped descriptor object which injects the PrefectDBInterface instance
* as the first argument to the function or method. This handles method
* binding transparently.

### `temporary_database_config` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L346](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L346)</sup>

```python theme={null}
temporary_database_config(tmp_database_config: Optional[BaseDatabaseConfiguration]) -> Generator[None, object, None]
```

Temporarily override the Prefect REST API database configuration.
When the context is closed, the existing database configuration will
be restored.

**Args:**

* `tmp_database_config`: Prefect REST API database configuration to inject.

### `temporary_query_components` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L367](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L367)</sup>

```python theme={null}
temporary_query_components(tmp_queries: Optional['BaseQueryComponents']) -> Generator[None, object, None]
```

Temporarily override the Prefect REST API database query components.
When the context is closed, the existing query components will
be restored.

**Args:**

* `tmp_queries`: Prefect REST API query components to inject.

### `temporary_orm_config` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L388](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L388)</sup>

```python theme={null}
temporary_orm_config(tmp_orm_config: Optional['BaseORMConfiguration']) -> Generator[None, object, None]
```

Temporarily override the Prefect REST API ORM configuration.
When the context is closed, the existing orm configuration will
be restored.

**Args:**

* `tmp_orm_config`: Prefect REST API ORM configuration to inject.

### `temporary_interface_class` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L409](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L409)</sup>

```python theme={null}
temporary_interface_class(tmp_interface_class: Optional[type['PrefectDBInterface']]) -> Generator[None, object, None]
```

Temporarily override the Prefect REST API interface class When the context is closed,
the existing interface will be restored.

**Args:**

* `tmp_interface_class`: Prefect REST API interface class to inject.

### `temporary_database_interface` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L429](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L429)</sup>

```python theme={null}
temporary_database_interface(tmp_database_config: Optional[BaseDatabaseConfiguration] = None, tmp_queries: Optional['BaseQueryComponents'] = None, tmp_orm_config: Optional['BaseORMConfiguration'] = None, tmp_interface_class: Optional[type['PrefectDBInterface']] = None) -> Generator[None, object, None]
```

Temporarily override the Prefect REST API database interface.

Any interface components that are not explicitly provided will be
cleared and inferred from the Prefect REST API database connection string
dialect.

When the context is closed, the existing database interface will
be restored.

**Args:**

* `tmp_database_config`: An optional Prefect REST API database configuration to inject.
* `tmp_orm_config`: An optional Prefect REST API ORM configuration to inject.
* `tmp_queries`: Optional Prefect REST API query components to inject.
* `tmp_interface_class`: Optional database interface class to inject

### `set_database_config` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L464](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L464)</sup>

```python theme={null}
set_database_config(database_config: Optional[BaseDatabaseConfiguration]) -> None
```

Set Prefect REST API database configuration.

### `set_query_components` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L469](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L469)</sup>

```python theme={null}
set_query_components(query_components: Optional['BaseQueryComponents']) -> None
```

Set Prefect REST API query components.

### `set_orm_config` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L474](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L474)</sup>

```python theme={null}
set_orm_config(orm_config: Optional['BaseORMConfiguration']) -> None
```

Set Prefect REST API orm configuration.

### `set_interface_class` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L479](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L479)</sup>

```python theme={null}
set_interface_class(interface_class: Optional[type['PrefectDBInterface']]) -> None
```

Set Prefect REST API interface class.

## Classes

### `DBInjector` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L239](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/database/dependencies.py#L239)</sup>
