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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for tinydb_constraint-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dacae4bebd6c9046198b7eb8ad61573271f76e24d196208f77f9ea2715f4833 |
|
MD5 | 6e27af445a4ce0c645813aeb2f11f540 |
|
BLAKE2b-256 | f15385b069efcf753859b2852e66da7a6da1c977d8062f65ce15fdaff0910bdb |