Objection.js has really good support for relational data as well as for JSONB data.
You don't have to do any tricks to parse / stringify json data. It all is done automatically. You can declare schemas to allow validating data you are going to put DB etc.
One can insert nested relational object hierarchies to DB and rows will be generated to correct tables and you have javascript API to query data inside JSON columns so no need to write RAW SQL for that either.
EDIT:
No idea why the down votes here (its -2 currently), Objection.js
still has the best support for Postgresql's JSONB operations in node world (and the only choice in current answers, which has any special support for postgresql jsonb handling).
Latest addition was support for patching only parts of data inside JSONB column, where objection.js automatically constructs jsonb_set()
calls for you.
for example:
ModelWithJsonColumn.query().update({
'jsonColumn:attribute' : 'new value',
otherColum: ref('jsonColumn:extractThisAttribute')
}).where('id', 1).returning('*')
will create update query like this:
update "ModelWithJsonColumn" set
"jsonColumn" = jsonb_set("jsonColumn", '{attribute}', to_jsonb('new value'), true),
"otherColumn" = "jsonColumn"#>'{extractThisAttribute}'
where "id" = 1 returning *
Also one can use ref()
syntax in pretty much every query builder method like in
.select(['id', ref('jsonArrayColumn:[0]')])
or
.where('name', ref('jsonColumn:middleName'))
or even with joins
.join('PetTable',
ref('PetTable.jsonColumn:details.name'),
'=',
ref('ThisTable.someOtherJsonbColumn:dogName'))