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.1.tar.gz (14.8 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.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tinydb-baseClass-0.1.1.tar.gz
  • Upload date:
  • Size: 14.8 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.1.tar.gz
Algorithm Hash digest
SHA256 d71a210d3a10243a549350f73068ac8637103498bc0b500d9fea1b92164fa1b7
MD5 e2c3185c523ab0ff88f7524a9bedb9e8
BLAKE2b-256 33e9d31ee41eb800c52901798088fbf887d34ac80b1a1fa6b80caaef7af695c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tinydb_baseClass-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00fa0c140a64e98878a16da5430cb5d30a5d8824edaad69d9e71b5a21293aed3
MD5 0487ccfff2b37c214052c97552b1b9c0
BLAKE2b-256 04cb987d39d22c9acdd8c12881ed2cd3a2f5a4a1bfcb9a72d01d7ab027498dd8

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