Skip to content

PantherPy/pantherdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI PyVersion Downloads license

Introduction

PantherDB is a Simple, FileBase and Document Oriented database that you can use in your projects.

Features:

  • Document Oriented
  • Easy to use
  • Written in pure Python +3.8 based on standard type hints
  • Handle Database Encryption
  • Singleton connection per db_name

Usage

Database:

  • Create a database:

    db: PantherDB = PantherDB('database.pdb')
  • Create an encrypted database:

    Required cyptography install it with pip install pantherdb[full]

    from cryptography.fernet import Fernet
    key = Fernet.generate_key()  # Should be static (You should not generate new key on every run)
    db: PantherDB = PantherDB('database.pdb', secret_key=key)
  • Access to a collection:

    user_collection: PantherCollection = db.collection('User')
  • Delete a collection:

    db.collection('User').drop()

Create:

  • Insert document:

    user: PantherDocument = db.collection('User').insert_one(first_name='Ali', last_name='Rn')

Get:

  • Find one document:

    user: PantherDocument = db.collection('User').find_one(first_name='Ali', last_name='Rn')

    or

    user: PantherDocument = db.collection('User').find_one()
  • Find first document (alias of find_one()):

    user: PantherDocument = db.collection('User').first(first_name='Ali', last_name='Rn')

    or

    user: PantherDocument = db.collection('User').first()
  • Find last document:

    user: PantherDocument = db.collection('User').last(first_name='Ali', last_name='Rn')

    or

    user: PantherDocument = db.collection('User').last()
  • Find documents:

    users: list[PantherDocument] = db.collection('User').find(last_name='Rn')

    or all documents

    users: list[PantherDocument] = db.collection('User').find()
  • Count documents:

    users_count: int = db.collection('User').count(first_name='Ali')

Update:

  • Update a document:

    user: PantherDocument = db.collection('User').find_one(first_name='Ali', last_name='Rn')
    user.update(name='Saba')
  • Filter and Update a document:

    _filter = {'first_name': 'Ali', 'last_name': 'Rn'}
    is_updated: bool = db.collection('User').update_one(_filter, first_name='Saba')
  • Filter and Update many:

    _filter = {'first_name': 'Ali'}
    updated_count: int = db.collection('User').update_many(_filter, first_name='Saba')

Delete:

  • Delete a document:

    user: PantherDocument = db.collection('User').first(first_name='Ali', last_name='Rn')
    user.delete()
  • Filter and Delete a document:

    is_deleted: bool = db.collection('User').delete_one(first_name='Ali', last_name='Rn')
  • Filter and Delete many:

    deleted_count: int = db.collection('User').delete_many(last_name='Rn')

TODO:

  • Add encryption
  • Complete tests TODO
  • Add B+ tree

About

Document Oriented File-Base Database

Topics

Resources

License

Stars

Watchers

Forks

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy