edelooff / sqlalchemy-json

Full-featured JSON type with mutation tracking for SQLAlchemy
http://variable-scope.com/posts/mutation-tracking-in-nested-json-structures-using-sqlalchemy
BSD 2-Clause "Simplified" License
189 stars 34 forks source link

Customizable storage type #25

Closed edelooff closed 4 years ago

edelooff commented 4 years ago

This adds a function mutable_json_type to create the actual column types for nested mutable structures, which resolves #22. Conveniently, this also exposes the actual storage type to tools like Alembic, which will now correctly try to create a table with a sa.JSON type.

It also fixes a regression bug introduced in #23 whereby SQLite (and potentially other engines) will no longer function due to not having a native JSON type for SQLAlchemy to interact with.

morganchristiansson commented 4 years ago

Ok nice. So existing (Nested)MutableJson class still works but is now instantiated from mutable_json_type() - which optionally replaces (Nested)MutableJson.

morganchristiansson commented 4 years ago

This is great. sqlalchemy-json will now work with TEXT colums in any database. Such as MySQL TEXT/LONGTEXT columns.

MariaDB doesn't have native JSON column type but aliases JSON to LONG for MySQL compatibility which works totally fine. They argue they get equivalent performance without having native JSON column implementation. https://mariadb.com/kb/en/json-data-type/

morganchristiansson commented 4 years ago

Our CI pipelines run fine using either JsonEncodedDict or mutable_json_type().

and alembic autogenerate says no pending changes which is good.

Seems fine to me - anything specific to test/look for?

edelooff commented 4 years ago

@morganchristiansson nothing specific to test, but a second pair of eyes helps, in addition to testing on MySQL/MariaDB as I don't have those ready to go here. I think that settles this PR, and should solve the regression introduced in 0.3.0.