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
+19-3Lines changed: 19 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,29 @@ SQLAlchemy-Nested-Mutable
5
5
pip install sqlalchemy-nested-mutable
6
6
```
7
7
8
-
An advanced SQLAlchemy column type factory that helps map complex Python types (e.g. `List`, `Dict`, *Pydantic Model* and their hybrids) to database types (e.g. `ARRAY`, `JSONB`),
8
+
An advanced SQLAlchemy column type factory that helps map compound Python types (e.g. `list`, `dict`, *Pydantic Model* and their hybrids) to database types (e.g. `ARRAY`, `JSONB`),
9
9
And keep track of mutations in deeply nested data structures so that SQLAlchemy can emit proper *UPDATE* statements.
10
10
11
11
SQLAlchemy-Nested-Mutable is highly inspired by SQLAlchemy-JSON<sup>[[0]](https://github.com/edelooff/sqlalchemy-json)</sup><sup>[[1]](https://variable-scope.com/posts/mutation-tracking-in-nested-json-structures-using-sqlalchemy)</sup>.
12
-
However, it does not limit the mapped Python type to be `Dict`.
12
+
However, it does not limit the mapped Python type to be `dict` or `list`.
13
13
14
-
Simple Example:
14
+
## Why this package?
15
+
16
+
* By default, SQLAlchemy does not track in-place mutations for non-scalar data types
17
+
such as `list` and `dict` (which are usually mapped with `ARRAY` and `JSON/JSONB`).
18
+
19
+
* Even though SQLAlchemy provides [an extension](https://docs.sqlalchemy.org/en/20/orm/extensions/mutable.html)
20
+
to track mutations on compound objects, it's too shallow, i.e. it only tracks mutations on the first level of the compound object.
21
+
22
+
* There exists the [SQLAlchemy-JSON](https://github.com/edelooff/sqlalchemy-json) package
23
+
to help track mutations on nested `dict` or `list` data structures.
24
+
However, the db type is limited to `JSON(B)`.
25
+
26
+
* Also, I would like the mapped Python types can be subclasses of the Pydantic BaseModelModel,
27
+
which have strong schemas, with the db type be schema-less JSON.
28
+
29
+
30
+
## Usage
15
31
16
32
> NOTE the example below is first updated in `examples/user-addresses.py` and then updated here.
0 commit comments