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
+70-7Lines changed: 70 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,76 @@ 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),
9
-
And keep track of mutations in deeply nested data structures so that SQLAlchemy can emit proper UPDATE statements.
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`),
9
+
And keep track of mutations in deeply nested data structures so that SQLAlchemy can emit proper *UPDATE* statements.
10
10
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>. However, it does not limit the mapped Python types to dict-like objects.
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
13
13
-
Documentation is not ready yet. Please refer to these test files for usage:
14
+
Simple Example:
14
15
15
-
* test_mutable_list.py
16
-
* test_mutable_dict.py
17
-
* test_mutable_pydantic_type.py
16
+
> NOTE the example below is first updated in `examples/user-addresses.py` and then updated here.
17
+
18
+
```python
19
+
from typing import Optional, List
20
+
21
+
import pydantic
22
+
import sqlalchemy as sa
23
+
from sqlalchemy.orm import Session, DeclarativeBase, Mapped, mapped_column
24
+
from sqlalchemy_nested_mutable import MutablePydanticBaseModel
25
+
26
+
27
+
classBase(DeclarativeBase):
28
+
pass
29
+
30
+
31
+
classAddresses(MutablePydanticBaseModel):
32
+
"""A container for storing various addresses of users.
33
+
34
+
NOTE: for working with pydantic model, use a subclass of `MutablePydanticBaseModel` for column mapping.
35
+
However, the nested models (e.g. `AddressItem` below) should be direct subclasses of `pydantic.BaseModel`.
0 commit comments