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: README.md
+10-5Lines changed: 10 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -195,7 +195,7 @@ The classes provide some common use methods:
195
195
196
196
*`get`: Retrieve a model by identifier
197
197
*`save`: Persist a model
198
-
*`save_many`: Persist multiple models in a single get_session
198
+
*`save_many`: Persist multiple models in a single transaction
199
199
*`delete`: Delete a model
200
200
*`find`: Search for a list of models (basically an adapter for SELECT queries)
201
201
@@ -215,11 +215,16 @@ using SQLAlchemy. It makes sense that the lifecycle of a `Session` follows the o
215
215
This ensures the `Session` we use is isolated, and the same for all the operations we do with the
216
216
same repository.
217
217
218
-
The consequence of these choices is we can't use SQLAlchemy lazy loading, so we need to make sure
219
-
relationship are loaded eagerly. You can do this by:
218
+
The session is automatically closed and reopen with each Repository operation, this make sure these
219
+
operation are independent from each other.
220
220
221
-
* Setup your model/table relationships to always use always eager loading
222
-
* Implement ad-hoc methods to deal with relationships as necessary
221
+
These choices cause some consequences:
222
+
* The operations that modify the database will reload the models from the DB, causing an additional
223
+
SELECT query to be issued.
224
+
* We can't use SQLAlchemy lazy loading, so we'll need to make sure relationship are always loaded eagerly,
225
+
using either:
226
+
* Setup your model/table relationships to always use always eager loading
227
+
* Implement ad-hoc methods to deal with relationships as necessary
223
228
224
229
Also `AsyncSession` has [the same limitation on lazy loading](https://docs.sqlalchemy.org/en/20/orm/extensions/asyncio.html#asyncio-orm-avoid-lazyloads)
225
230
so it makes sense that the two repository implementations behave consistently.
0 commit comments