Better HN
topnewbestaskshowjobs
Log inSign up

throwaway76324

2 karma · joined Jul 8, 2024 (2y ago) · 2 submissions

Submissions

comment 2y ago · link · parent

You can just specify a model/DTO object and serialize it as JSON when saving. Many frameworks do that automatically so you don't need to think about it. At work we just annotate the field in the model as a json-field, and the framework will handle the json-conversion automatically and store the other fields in the model as regular database columns.

pseudo code (to not trigger language wars):

   class Foo {
   
       @Id
       UUID id;

       String name;

       @Json
       MyCustomModel model;
   }
Adding fields is not an issue, as it will simply be missing a value when de-serializing. Your business logic will need to handle its absence, but that is no different than using MongoDB or "classic" table columns

comment 2y ago · link · parent

At $WORK, we use the same approach for integrations with 3rd party systems.

The data that is common for all integrations are stored as columns in a relational table. Data that are specific for each integration are stored in JSONB. This is typically meta data used to manage each integration that varies.

It works great and you get the combination of relational safety and no-schema flexibility where it matters.