deepkit-framework icon indicating copy to clipboard operation
deepkit-framework copied to clipboard

use same serializer for reads as writes

Open fergusean opened this issue 3 years ago • 3 comments

Signed-off-by: fergusean [email protected]

Summary of changes

When creating a custom class to support database features and registering a serializer and deserializer, it seems the base SQL adapter uses a different registry for serialization (adapter.platform.serializer.serializerRegistry) to the database than it does for deserialization from the database (sqlSerializer.deserializerRegistry). This PR aligns them to use the same.

Relinquishment of Rights

Please mark following checkbox to confirm that you relinquish all rights of your changes:

  • [X] I waive and relinquish all rights regarding this changes (including code, text, and images) to Deepkit UG (limited), Germany. This changes (including code, text, and images) are under MIT license without name attribution, copyright notice, and permission notice requirement.

fergusean avatar Jul 21 '22 02:07 fergusean

Codecov Report

Merging #324 (5d6e43a) into master (b45ede8) will decrease coverage by 0.29%. The diff coverage is n/a.

:exclamation: Current head 5d6e43a differs from pull request most recent head e1789a0. Consider uploading reports for the commit e1789a0 to get more accurate results

@@            Coverage Diff             @@
##           master     #324      +/-   ##
==========================================
- Coverage   78.31%   78.01%   -0.30%     
==========================================
  Files         169      164       -5     
  Lines       17672    17118     -554     
  Branches     4615     4492     -123     
==========================================
- Hits        13839    13354     -485     
+ Misses       3833     3764      -69     
Impacted Files Coverage Δ
packages/sqlite/src/sqlite-adapter.ts
packages/sqlite/src/sql-filter-builder.sqlite.ts
packages/sqlite/src/sqlite-serializer.ts
packages/sqlite/src/sqlite-schema-parser.ts
packages/sqlite/src/sqlite-platform.ts

:mega: Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

codecov-commenter avatar Jul 21 '22 02:07 codecov-commenter

image image image

So this is interesting... moderation is a JSON string stored in SQLite. When I apply this PR, SQLite's boolean deserializer kicks in on not only SQLite's properties, but also the properties of the parsed JSON from the moderation field.

I would think for databases, JSON parsed objects should use the base deserializer, rather than the SQL platform's serializer, since root properties may be transformed in special ways (in/out of the DB driver) that would not apply to subobjects (such as embedded JSON).

Thoughts?

fergusean avatar Jul 21 '22 04:07 fergusean

Oh, good catch, yes that's right! JSON fields should not use the database serializer.

marcj avatar Jul 27 '22 16:07 marcj

@fergusean fixed in https://github.com/deepkit/deepkit-framework/commit/e5bf873381eff60af5c3c62132276695a79d9c5c

marcj avatar Dec 01 '22 05:12 marcj

sweet thanks!!

fergusean avatar Dec 01 '22 05:12 fergusean