Skip to content

Commit f63904f

Browse files
committed
readme: why this package
1 parent 30fc336 commit f63904f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@ SQLAlchemy-Nested-Mutable
55
pip install sqlalchemy-nested-mutable
66
```
77

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`),
99
And keep track of mutations in deeply nested data structures so that SQLAlchemy can emit proper *UPDATE* statements.
1010

1111
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`.
1313

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
1531

1632
> NOTE the example below is first updated in `examples/user-addresses.py` and then updated here.
1733

0 commit comments

Comments
 (0)