Skip to main content

Apply constraints before inserting and updating TinyDB records.

Project description

tinydb-constraint

Apply constraints before inserting and updating TinyDB records.

Installation

Method 1:

$ pip install tinydb-constraint

Method 2:

  • Clone the project from GitHub
  • Get poetry and poetry install tinydb-constraint --path PATH/TO/TINYDB/CONSTRAINT

Usage

>>> from tinydb import TinyDB
>>> from tinydb_constraint import ConstraintTable
>>> from datetime import datetime
>>> db = TinyDB('db.json')
>>> db.table_class = ConstraintTable
>>> db.schema = {
...     'record_id': int,
...     'modified': datetime
... }

If you want to enable TinyDB-constraint for all databases in a session, run:

>>> from tinydb import TinyDB
>>> from tinydb_constraint import ConstraintTable
>>> TinyDB.table_class = ConstraintTable

Note

I haven't modified the serialization yet, so datetime type will actually produce datetime.isoformat(), and to set datetime, you have to pass a dateutil.parser.parse()-parsable string.

Related projects

  • tinydb-viewer - View records generated from TinyDB and alike (e.g. list of dictionaries.)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinydb-constraint-0.1.0.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

tinydb_constraint-0.1.0-py2.py3-none-any.whl (7.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page