## protocols.daopub.DaoPublisherFactoryProtocol

<span id="hexkit.protocols.daopub.DaoPublisherFactoryProtocol"></span>


A protocol describing a factory to produce Data Access Objects (DAO) objects


Usage

``` python
protocols.daopub.DaoPublisherFactoryProtocol()
```


which automatically publish changes according to the outbox pattern.


## Methods

| Name | Description |
|----|----|
| [get_dao()](#get_dao) | Constructs an Outbox DAO for interacting with resources in a database. |

<span id="hexkit.protocols.daopub.DaoPublisherFactoryProtocol.get_dao"></span>


#### get_dao()


Constructs an Outbox DAO for interacting with resources in a database.


Usage

``` python
get_dao(
    *,
    name,
    dto_model,
    id_field,
    indexes=None,
    dto_to_event,
    event_topic,
    autopublish=True
)
```


##### Parameters


`name: str`  
The name of the resource type (roughly equivalent to the name of a database table or collection).

`dto_model: type[Dto]`  
A DTO (Data Transfer Object) model describing the shape of resources.

`id_field: str`  
The name of the field of the `dto_model` that serves as resource ID. (DAO implementation might use this field as primary key.)

`indexes: Collection[Index] | None = None`  
Optionally, provide any indexes that should be created in addition to the provider's default index on `id_field`. Defaults to None.

`dto_to_event: Callable[[Dto], JsonObject | None]`  
A function that takes a DTO and returns the payload for an event. If the returned payload is None, the event will not be published.

`event_topic: str`  
The topic to which events should be published.

`autopublish: bool = ``True`  
Whether to automatically publish changes. Defaults to True.


##### Returns


`DaoPublisher[Dto]`  
A DAO of type DaoPublisher, which requires ID specification upon resource

creation.


##### Raises


`self.IdFieldNotFoundError`  
Raised when the dto_model did not contain the expected id_field.

`self.IdTypeNotSupportedError`  
Raised when the id_field of the dto_model has an unexpected type.
