AdonisJS Lucid and PostgreSQL JSONB object serialization at the model boundary
0 reputation · 30 Mar 2025, 01:55 UTC
The goal is to read a PostgreSQL JSONB column through an AdonisJS Lucid model as a plain JavaScript object after fetch, and to write a plain object back on save without manual stringification in application code.
Lucid does not document guaranteed automatic JSONB casting, and behavior may differ between AdonisJS 5 and Lucid in AdonisJS 6. The node-pg type parser can return JSONB as text or parsed JSON independently of the ORM, and schema builder support for json or jsonb columns depends on the installed major version and driver. Until the installed version is confirmed, nested attribute round-trips cannot be assumed to survive as objects.
Does Lucid cast a PostgreSQL JSONB column to a JavaScript object on model fetch, or does it return a string? Is an object assigned to a JSONB attribute serialized automatically on save, or are getter and setter accessors required? Which AdonisJS major version and node-pg type-parser settings control this boundary behavior?