Skip to content

Commit

Permalink
Add doc note for initial jsonb support.
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
coleifer committed Mar 21, 2024
1 parent adad27b commit 65fd91f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/peewee/sqlite_ext.rst
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,35 @@ APIs
JSON object at the given location. See also :py:meth:`JSONField.tree`.


.. py:class:: JSONBField(json_dumps=None, json_loads=None, ...)
Field-class suitable for use with data stored on-disk in ``jsonb`` format
(available starting Sqlite 3.45.0). This field-class should be used with
care, as the data may be returned in it's encoded format depending on how
you query it. For example:

.. code-block:: pycon
>>> KV.create(key='a', value={'k1': 'v1'})
<KV: 1>
>>> KV.get(KV.key == 'a').value
b"l'k1'v1"
To get the JSON value, it is necessary to use ``fn.json()`` or the helper
:py:meth:`JSONBField.json` method:

.. code-block:: pycon
>>> kv = KV.select(KV.value.json()).get()
>>> kv.value
{'k1': 'v1'}
.. py:class:: JSONBPath(field[, path=None])
Subclass of :py:class:`JSONPath` for working with ``jsonb`` data.


.. py:class:: SearchField([unindexed=False[, column_name=None]])
Field-class to be used for columns on models representing full-text search
Expand Down
3 changes: 3 additions & 0 deletions playhouse/sqlite_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ def db_value(self, value):
value = fn.jsonb(self._json_dumps(value))
return value

def json(self):
return fn.json(self)

def extract(self, *paths):
paths = [Value(p, converter=False) for p in paths]
return fn.jsonb_extract(self, *paths)
Expand Down

0 comments on commit 65fd91f

Please sign in to comment.