Tinydb CRUD wrapper for table
Project description
Tinydb Helper
A Tinydb crud wrapper that make crud operations a breeze
Installation
You can install the package using pip:
pip install tinydb-helper
Usage
This package will install Tinydb
from tinydb_helper.helper import Table
from tinydb import TinyDB
import time
def main() -> None:
db = TinyDB("db.json")
timestamp = str(int(time.time()))
# Exemple creating project table with custom primary key using default primary key generator
project = Table(db=db, table="project", primary_key="proj_id")
# Example creating person table with custom primary key generator
person = Table(db=db, table="person", key_gen=lambda: timestamp)
# Example inserting a few record in person and project tables
for i in range(4):
project.insert(dict(name=f"test-{i}", year=f"{2004 + i}"), id=str(i + 1))
person.insert(dict(first=f"first-{i}", year=f"{2004 + i}", id=str(i + 1)))
# Exemple get all object from table person
person.all()
# Exemple find person object matching primary key field equal to "0"
person.find(id="0")
# Exemple update person object matching primary key field equal to "0"
person.update(id="0", item=dict(test='pass'))
# Exemple delete person object matching primary key field equal to "0"
person.delete(id="0")
if __name__ == "__main__":
main()
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_helper-0.1.4.tar.gz
(2.5 kB
view details)
Built Distribution
File details
Details for the file tinydb_helper-0.1.4.tar.gz
.
File metadata
- Download URL: tinydb_helper-0.1.4.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28c6f225999b60ea1280b423ab813300994cfc35cee4daa624988a89bad1f650 |
|
MD5 | 869122ed371262f283d3caf74ef4ec8a |
|
BLAKE2b-256 | f75dc7771ec334cbb3bdd1b56ab2ab82585f5fb2eba809203994a832fdb744a8 |
File details
Details for the file tinydb_helper-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: tinydb_helper-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fac868b021dac61a29b429e009ee58096bd52a936b496a88159cabc59a2e82f |
|
MD5 | 85efca36a010e401786623635df2dcfb |
|
BLAKE2b-256 | 7481ab5b2ab5b75f1883ea9ccaffe3de7c123e96c1d65ebf76ff0705117afad6 |