Skip to main content

a base class to tinydb

Project description

TinyDB base

I use TinyDB ... a lot and very often and i seem to be writing the same functions over and over. The idea behind the small project to provide a way for devs to easily create a data modal around tinydb without the need to build a base class.

How to install

the easiest way is to install through your dependency manager pip install tinyDbBase or if using pipenv install tinyDbBase.

How do i use this thing

Factory

This allows you to interact with Tinydb and both the root object and a table in the same object.

    from tinydb_base import Factory

    db = Factory('myData.json', 'myTable')
    db.db # equliervent to `TinyDB`.
    db.tbl # equliervent to `TinyDB.Table`.

    db.close() # closes the database file.

DatabaseBase

the idea is to import the base class and then derives into your own class. the idea is that you can simply create your data layer by creating a class that will work out what needs and just work.

    from tinydb_base import DatabaseBase

    class MyTable(DatabaseBase):

        def __init__(self, file='ds.json', table=__name__, requiredKeys=['title']):
            super().__init__(file=file, table=table, requiredKeys=requiredKeys)


    MyTable().create({'title': 'foobar'})

This will enable to accesses the base class, you can add your own custom functions. the will use the namespaces of the file within the project, but you can override this easily at an instance. another cool feature is that required keys this is key that must be present in every row which can also be changed.

methods

Method Name attr Description
create dict this adds a new row to the database.
createMultiple list of dicts this added multiple rows
readAll returns a list obj
readById id this gets a row by the id
removeById id this removes a row by id

DatabaseBaseSercure

this works exactly the same way as DatabaseBase but by providing a salt you can encrypt using Fernet, it is suggested that you define your own salt

from tinydb_base.cryptography import DatabaseBaseSercure


class Diary(DatabaseBaseSercure):

    def __init__(self, file='ds.json', table=__name__, requiredKeys=['title'], salt='salt'):
        super().__init__(file=file, table=table, requiredKeys=requiredKeys, salt=salt)


obj = Diary(salt='thisisasalt')

GetSet

this is a very simple interface that sets and gets values based on a tag. this can be used for things like settings. if the tag dose did not exist the class will raise tinydb_base.exceptions.RowNotFound_Exception

from tinydb_base.getSet import GetSet

class Settings(GetSet):

    def __init__(self, file: str = 'ds.json', table: str = __name__):
        super().__init__()

Settings().set('foo', 'bar')
Settings().get('foo')

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-baseClass-0.1.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinydb_baseClass-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file tinydb-baseClass-0.1.0.tar.gz.

File metadata

  • Download URL: tinydb-baseClass-0.1.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for tinydb-baseClass-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9814216b5308c27dc178ad3819445b3fc76638d42b15f5ca24c52746521c19a1
MD5 5f2e5e6a141e8a05ceffc2fcb5f0f7ef
BLAKE2b-256 e9edef7f6bc43fd70460a479b849e1621accf48b9b0b6e90b681de8644167363

See more details on using hashes here.

File details

Details for the file tinydb_baseClass-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tinydb_baseClass-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for tinydb_baseClass-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b758aae71db8181eb9cf7d4e20a7bebd80338eb52682e5dd97186e13b50dab94
MD5 04b56f98fcb33f0165eae52cc295b703
BLAKE2b-256 5d2e411b9275dc5f6ace56fefa0ff14e464b50b35c39345045ebc30c1cbaf5fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page