Skip to content

Commit 8769692

Browse files
committed
Add information about repository protocols
1 parent fdc7750 commit 8769692

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/repository/repository.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ The classes provide some common use methods:
2929
* `paginated_find`: Search for a list of models, with pagination support
3030
* `cursor_paginated_find`: Search for a list of models, with cursor based pagination support
3131

32+
/// details | Typing and Protocols
33+
type: tip
34+
35+
The repository classes are fully typed (as the rest of this package), but
36+
protocols classes are provided as addition to allow more decoupled type checking
37+
and inversion of control patterns such as
38+
[dependency injection](https://en.wikipedia.org/wiki/Dependency_injection).
39+
40+
```python
41+
from sqlalchemy_bind_manager.protocols import SQLAlchemyRepositoryInterface, SQLAlchemyAsyncRepositoryInterface
42+
43+
def some_function(repository: SQLAlchemyRepositoryInterface[MyModel]):
44+
model = repository.get(123)
45+
...
46+
47+
async def some_async_function(repository: SQLAlchemyAsyncRepositoryInterface[MyModel]):
48+
model = await repository.get(123)
49+
...
50+
```
51+
52+
Both repository and related protocols are Generic, accepting the model class as argument.
53+
///
54+
3255
### Maximum query limit
3356

3457
Repositories have a maximum limit for paginated queries defaulting to 50 to

0 commit comments

Comments
 (0)