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
>>> TinyDB.table_class = ConstraintTable
>>> db = TinyDB('db.json')
>>> db.set_schema({
... 'record_id': int,
... 'modified': datetime
... })
>>> db.schema
{
'record_id': Constraint(type_=int, unique=False, not_null=False),
'modified': Constraint(type_=datetime.datetime, unique=False, not_null=False)
}
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.
Advanced usage
Database schema is also settable via Constraint object.
>>> from tinydb_constraint import Constraint
>>> db.set_schema({
... 'user_id': Constraint(type_=int, unique=True, not_null=True)
... })
If you want to disable certain string sanitization features, like stripping spaces or checking if string can be converted to datetime, this can be done by setting environmental variables.
TINYDB_SANITIZE=0
TINYDB_DATETIME=0
Plan
- Add ForeignKey constraints.
Related projects
- tinydb-viewer - View records generated from TinyDB and alike (e.g. list of dictionaries.)
Release files for tinydb-constraint 0.1.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tinydb-constraint-0.1.8.1.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tinydb_constraint-0.1.8.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 20.8 kB
Release files / tinydb-constraint-0.1.8.1.tar.gz
| Download URL | tinydb-constraint-0.1.8.1.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eb12ba9c7cf9bc6852e0efce1dc1a9c2aeee07f50c61ac40cb00f88077d94caf
|
|
BLAKE2b-256 checksum How to use checksums |
55c531039dae1c1def437a1b0422e837b6fd99e42aef241074a0e1bd51ab9e32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.11.5 CPython/3.7.0 Darwin/17.7.0
|
Release files / tinydb_constraint-0.1.8.1-py2.py3-none-any.whl
| Download URL | tinydb_constraint-0.1.8.1-py2.py3-none-any.whl |
|---|---|
| Size | 15.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
8672925ab93f453597ad7db877ff61d311a386ba73b939b966b6b3af1e825119
|
|
BLAKE2b-256 checksum How to use checksums |
e2696990be9abc1ef0f6e703239fc1077bb7247aaaee463873beebb230ec8230
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.11.5 CPython/3.7.0 Darwin/17.7.0
|