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.3.tar.gz
(2.5 kB
view details)
Built Distribution
File details
Details for the file tinydb_helper-0.1.3.tar.gz
.
File metadata
- Download URL: tinydb_helper-0.1.3.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3a3fc6383bac1d4459e6c8bbe690ffeff8cabb58134e46da50d710360ea8103 |
|
MD5 | b27711174ac92e9d651de1192912e6d2 |
|
BLAKE2b-256 | 7059074edc08570d733c1536c95360008595793aa630a7fa927a57ba09ac349d |
File details
Details for the file tinydb_helper-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: tinydb_helper-0.1.3-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.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 645469aa66fa0a9c4bd9bc6c85b4b7da99df75664f089eaffd129b760e165d44 |
|
MD5 | e8700d3c2552f6aa1cd64fcaf4a5f96b |
|
BLAKE2b-256 | 003735857a5dccd6f07de3ca36df66982cf1932bb3e55314811a39ee89df34ef |