You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/lifecycle.md
+23-56Lines changed: 23 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,70 +17,37 @@ From SQLAlchemy documentation:
17
17
recommends we create `Session` object at the beginning of a logical operation where
18
18
database access is potentially anticipated.
19
19
20
-
The repository is not built for parallel execution, it keeps a `Session` object scoped to
21
-
its lifecycle to avoid unnecessary queries, and executes a transaction for each _operation_
22
-
to maintain isolation. This means you can create a repository object almost whenever you want,
23
-
as long as you don't run parallel operations.
24
-
25
-
The session in the repository is not thread safe and [is not safe on concurrent asyncio tasks](https://docs.sqlalchemy.org/en/20/orm/session_basics.html#is-the-session-thread-safe-is-asyncsession-safe-to-share-in-concurrent-tasks)
26
-
therefore the repository has the same limitations.
27
-
28
-
This means:
29
-
30
-
* Do not assign a repository object to a global variable
31
-
(Check the [Notes on multithreaded applications](/manager/session/#note-on-multithreaded-applications))
32
-
* Do not share a repository instance in multiple threads or processes (e.g. using `asyncio.to_thread`).
33
-
* Do not use the same repository in concurrent asyncio task (e.g. using `asyncio.gather`)
34
-
35
-
Even using multiple repository instances will work fine, however as they will have completely
36
-
different sessions, it's likely that the second repository will fire additional SELECT queries
37
-
to get the state of the object prior to saving it.
38
-
39
-
/// details | Example
40
-
```python
41
-
from sqlalchemy import String
42
-
from sqlalchemy.orm import Mapped, mapped_column
43
-
from sqlalchemy_bind_manager import SQLAlchemyBindManager ,SQLAlchemyConfig
44
-
from sqlalchemy_bind_manager.repository import SQLAlchemyRepository
0 commit comments