Add sqlite.JSONB type for binary JSON storage (SQLite >= 3.45.0)
Added :class:`_sqlite.JSONB` type for SQLite's binary JSON storage format, available as of SQLite version 3.45.0. Values are stored via the ``jsonb()`` SQL function and retrieved via ``json()``, while the Python-side behavior remains identical to :class:`_sqlite.JSON`. Pull request courtesy Shamil Abdulaev. Fixes: #13260 Adds `sqlalchemy.dialects.sqlite.JSONB` — a new dialect-specific type for SQLite's binary JSON storage format, introduced in SQLite 3.45.0. The type: - renders `JSONB` in DDL (`CREATE TABLE t (col JSONB)`) - wraps bind values with `jsonb()` on write, storing data as a BLOB - wraps column reads with `json()`, returning standard text JSON to Python - reflects back from the database as `sqlite.JSONB` - behaves identically to `sqlite.JSON` on the Python side SQLite 3.45.0 introduced a native binary JSON format (JSONB) that is more compact and faster to parse than text JSON. Users who want to opt into this storage format had no way to do so via SQLAlchemy. - `JSONB` inherits from `sqlite.JSON` and defines `__visit_name__ = "JSONB"` so the DDL compiler dispatches to `visit_JSONB` instead of `visit_JSON` - Added `JSONB: JSONB` to `colspecs` so the type is not remapped to `_SQliteJson` via the `sqltypes.JSON` MRO entry - `bind_expression` / `column_expression` apply `jsonb()` / `json()` transparently; existing `result_processor` from `sqltypes.JSON` handles deserialization without changes - Added `sqlite_jsonb` requirement (checks for SQLite >= 3.45 and that `jsonb()` is available, since it is a loadable extension) `test/dialect/sqlite/test_types.py::JSONBTest` (8 tests): - DDL renders `JSONB` - Reflection returns `sqlite.JSONB` - Round-trip read/write including `None` - Sub-object extraction via `[]` indexing - Compiled SQL shows `jsonb(?)` on INSERT and `json(col)` on SELECT - `typeof(col)` returns `blob` confirming binary storage Closes: #13261 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13261 Pull-request-sha: 81b93af698e0222a9262614d39dd5ade6b640273 Change-Id: Ic38704674d30aa3d1bb5ce1e8ef5e4b0562ad91a
S
Shamil Abdulaev committed
0aa47f8082513ecccc1638558f46b9fe8e610ad2
Parent: dcb36d7
Committed by Michael Bayer <mike_mp@zzzcomputing.com>
on 5/7/2026, 5:59:09 PM