Skip to main content

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, Query
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 filter person table base on Tinydb Query conditions
    person.filter(Query()['first'] == 'first-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.5.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

tinydb_helper-0.1.5-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file tinydb_helper-0.1.5.tar.gz.

File metadata

  • Download URL: tinydb_helper-0.1.5.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

Hashes for tinydb_helper-0.1.5.tar.gz
Algorithm Hash digest
SHA256 81fcb85ebbfd63ea4edd6890b61eae095bd23b7d1f7aaa9a1f8beea37e8d7d1f
MD5 7de351529e068a45bbd4d2e3941681e9
BLAKE2b-256 f0d968fe39c46b3c15fde4b67908e922f0d618c623287583630d0e9993125364

See more details on using hashes here.

File details

Details for the file tinydb_helper-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: tinydb_helper-0.1.5-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

Hashes for tinydb_helper-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7d86b472f1f583e297a73bafa03cbf2cced6720d78e171538d5b202d92da102e
MD5 98827c5ca9fd447889e30e4e60240df0
BLAKE2b-256 61fa3a4d37f2a00e1cce5fa76ec1fe3533da7c6520062af094f66afa1ec9383f

See more details on using hashes here.

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