Skip to main content

Document based light weight NoSQL database.

Project description

touchdb

touchdb is a simple document based nosql database built entirely on python. This save the data input which is in python dictionary into a JSON data in a .db file. There are only limited number of functionalities that are implemented in the engine but they are more than sufficient to handle normal database queries.

Find Me

Installation

Easy to install in your projects using pip.
pip install touchdb

Usage

>>> from touchdb import Database
>>> db = Database.Connector('./record.db', True)
>>> print(db.getByAttribute(record_type='sickness', patient_id='usr1'))

List of functions

  1. load(location, auto_dump) : Force the database to load the database from the database file into the memory.
  2. dump() : Dump the data in the memory into the database file.
  3. insert(**kwargs) : Insert the python dictionary data into the database. key - optional parameter which provide the key for the value to be inserted. value is python dict to be inserted into the database.
  4. get(key) : Get the data from the database using the key.
  5. getAll() : Get all the data in the database as JSON format(python dictionary).
  6. getByAttribute(**kwargs) : Attribute of the record will be checked with the provided values and return the list of mapping data in the database.
  7. exists(key) : Check if a key exists in the database.
  8. remove(key) : Remove a particular data mapping to the key in the database.
  9. removeByAttribute(**kwargs) : Remove all data records in the database which correlate to the attribute value.
  10. totalkeys(key=None) : If the parameter key is not provided return the total number of keys in the database, but if the key is provided return the number of data records 11. inside that particular dictionary.
  11. add(key, value:dict) : Add a new key-value pair to the existing data record with key as provided.
  12. extend(datas: dict) : Extend the database with the provided dictionary data.
  13. deldb() : Delete the database from both memory and file.


Sample Data

A sample data record file is given below for testing purpose.

{
    "894a9a5d-46e8-11ed-b600-b526d12bcc50": {
        "patient_id": "usr1",
        "patient_name": "James",
        "record_type": "sickness",
        "sens_level": 4,
        "data": "<THIS IS THE ACTUAL DATA TO BE STORED IN THE DATABASE>"
    },
    "69840102-479e-11ed-97ec-b526d12bcc50": {
        "patient_id": "usr6",
        "patient_name": "Kabilan",
        "record_type": "sickness",
        "sens_level": 3,
        "data": "THIS IS A DUMMY SICKNESS DATA FOR NEW USER"
    },
    "4e4f3d76-47b0-11ed-8752-b526d12bcc50": {
        "patient_id": "usr7",
        "patient_name": "Levi Ackerman",
        "record_type": "drug_prescription",
        "sens_level": 3,
        "data": "THIS IS A DUMMY DRUG PRESCRIPTION DATA RECORD FOR TESTING"
    }
}

A few example code

from touchdb import Database

db = Database.Connector('./record.db', True)
db.insert(value={'test_id':"test123"})
print(db.get(key='cf9a67ed-4bf6-11ed-9284-b72b6fa7f086'))
print(db.getAll())
print(db.getByAttribute(record_type='sickness'))
print(db.exists(key='cf9a67ed-4bf6-11ed-9284-b72b6fa7f086'))
print(db.remove(key='cf9a67ed-4bf6-11ed-9284-b72b6fa7f086'))
print(db.removeByAttribute(record_type='sickness'))
print(db.totalkeys())
print(db.totalkeys(key='69840102-479e-11ed-97ec-b526d12bcc50'))
print(db.add('4e4f3d76-47b0-11ed-8752-b526d12bcc50', {'address':'Eldian Kingdom', 'Kill count':'inf+'}))

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

touchdb-0.0.5.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

touchdb-0.0.5-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file touchdb-0.0.5.tar.gz.

File metadata

  • Download URL: touchdb-0.0.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for touchdb-0.0.5.tar.gz
Algorithm Hash digest
SHA256 3e7307e3e4bc3392bf5d9901753ac153c50b04768b96dca920a299185371d1eb
MD5 869f0fd8ec43132d9d52e25fe8ed12bb
BLAKE2b-256 1121e257d65b75f570263c317e8f335665e469cf13ecbda940038d830115be6b

See more details on using hashes here.

File details

Details for the file touchdb-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: touchdb-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for touchdb-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9ad58b0fa8c30229acb0a97fb3e94b6854433f9f2e5efc4c841ba8df00c8f74c
MD5 c2ef68a6eeed3ab206d38ab01670dcb1
BLAKE2b-256 623ec02fbd1d5b6d09c70131e616715e93ec0448a3d04c4a2650d1d3d51248eb

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