My application uses the SQLalchemy ORM code exclusively to define the database schema. For the database, two uses cases exist. For the sake of simplicity, I'll call the first the "simple" use case, the second the "complex" use case.
Both use cases go through my application. Both use cases generate JSON data. However, the use cases differ on how the JSON data is queried later on; consequently, the reports that run on the database make use of the same application/library code, but construct different queries on the JSON attributes of the schema.
Now, the simple use case employs exclusively SQLite, while the complex use case relies on PostgreSQL exclusively. I would like to use JSONB
on PostgreSQL, because all reports that run against the PostgreSQL database cast all JSON
fields to JSONB
. SQLite, however, does not have JSONB
, obviously. Still, I would like to use the same ORM code in both cases.
How can I make SQLalchemy use JSONB
when my code connects to a PostgreSQL database, but JSON
in all other cases? I.e., can I change the facade of JSON
for the PostgreSQL dialect?