Home Database Mysql Tutorial HadiDB: A lightweight, horizontally scalable database in Python

HadiDB: A lightweight, horizontally scalable database in Python

Apr 08, 2025 pm 06:12 PM
python git key value pair pip installation

HadiDB: A lightweight, horizontally scalable database in Python

HadiDB: Lightweight, high-level scalable Python database

HadiDB (hadidb) is a lightweight database written in Python that has a high level of scalability.

Install HadiDB

Install using pip:

 <code class="bash">pip install hadidb</code>
Copy after login

User Management

Create a user: createuser() method creates a new user. authentication() method authenticates the user's identity.

 <code class="python">from hadidb.operation import user user_obj = user("admin", "admin") user_obj.createuser() # 创建用户user_obj.authentication() # 验证用户</code>
Copy after login

Return the result example:

 <code class="json">{'status': 200, 'message': 'database user created'}</code>
Copy after login

Database, collection, and schema creation

The following code snippet shows how to set up user credentials, database collection schema, and how to insert data.

 <code class="python">from hadidb.operation import operation username = "admin" password = "admin" database = "mefiz.com" collection = "authuser" schema = { "username": "unique", "password": "hash", "cnic": "unique", "picture": "image", "bio": "text" } db = operation(username, password, database, collection) db.create_database(schema)</code>
Copy after login

Data operation

  • Insert data: db.insert(data) method inserts data.
 <code class="python">data = { "username": "hadidb", "password": "12345", "cnic": "123232442", "picture": "user/my/hadidb.jpg", "bio": "hadidb is the best ;)" } result = db.insert(data) print(result)</code>
Copy after login

Return the result example:

 <code class="json">{ 'status': 200, 'message': 'data insert successfully', 'data': { 'username': 'hadidb', 'password': '12345', 'cnic': '123232442', 'picture': 'user/my/hadidb.jpg', 'bio': 'hadidb is the best ;)', 'id': 1 } }</code>
Copy after login
  • Update data: db.update(1, update_data) method updates data.
 <code class="python">update_data = { "username": "hadidb_update", "password": "123455", "cnic": "1232324423", "picture": "user/my/hadidb1.jpg", "bio": "hadidb is the best ;) update bio" } result = db.update(1, update_data) print(result)</code>
Copy after login
  • Get data by ID: db.getbyid(1) method Get data by ID.

  • Get all data: db.getall() method gets all data.

  • Press the key to get data: db.getbykey() and db.getbykeys() methods use the key to get data.

  • Count: The number of data statistics of db.count() method. db.getbykeycount() method counts the number of data matching the specified key-value pair.

  • Delete data: db.delete(1) method deletes data.

Database and collection management

  • Get all databases: configuration().get_database() method gets all databases.

  • Get all collections: configuration(database).get_collection() method gets all collections of the specified database.

  • Get the pattern: configuration(database, collection).get_schema() method gets the pattern of the specified collection.

  • Delete collection: databasedeletionservice().deletecollection() method deletes collection.

  • Delete the database: databasedeletionservice().deleteDatabase() method deletes the database.

Project link

This version reorganized and polished the original text to make it clearer and easier to read, and formatted the code sections to make it easier to understand. All image links are retained.

The above is the detailed content of HadiDB: A lightweight, horizontally scalable database in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The 2-Hour Python Plan: A Realistic Approach The 2-Hour Python Plan: A Realistic Approach Apr 11, 2025 am 12:04 AM

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

How to implement the underlying redis How to implement the underlying redis Apr 10, 2025 pm 07:21 PM

Redis uses hash tables to store data and supports data structures such as strings, lists, hash tables, collections and ordered collections. Redis persists data through snapshots (RDB) and append write-only (AOF) mechanisms. Redis uses master-slave replication to improve data availability. Redis uses a single-threaded event loop to handle connections and commands to ensure data atomicity and consistency. Redis sets the expiration time for the key and uses the lazy delete mechanism to delete the expiration key.

How to clean all data with redis How to clean all data with redis Apr 10, 2025 pm 05:06 PM

How to clean all Redis data: Redis 2.8 and later: The FLUSHALL command deletes all key-value pairs. Redis 2.6 and earlier: Use the DEL command to delete keys one by one or use the Redis client to delete methods. Alternative: Restart the Redis service (use with caution), or use the Redis client (such as flushall() or flushdb()).

How to view all keys in redis How to view all keys in redis Apr 10, 2025 pm 07:15 PM

To view all keys in Redis, there are three ways: use the KEYS command to return all keys that match the specified pattern; use the SCAN command to iterate over the keys and return a set of keys; use the INFO command to get the total number of keys.

How to read redis queue How to read redis queue Apr 10, 2025 pm 10:12 PM

To read a queue from Redis, you need to get the queue name, read the elements using the LPOP command, and process the empty queue. The specific steps are as follows: Get the queue name: name it with the prefix of "queue:" such as "queue:my-queue". Use the LPOP command: Eject the element from the head of the queue and return its value, such as LPOP queue:my-queue. Processing empty queues: If the queue is empty, LPOP returns nil, and you can check whether the queue exists before reading the element.

How to use the redis command How to use the redis command Apr 10, 2025 pm 08:45 PM

Using the Redis directive requires the following steps: Open the Redis client. Enter the command (verb key value). Provides the required parameters (varies from instruction to instruction). Press Enter to execute the command. Redis returns a response indicating the result of the operation (usually OK or -ERR).

How to deal with Redis memory fragmentation? How to deal with Redis memory fragmentation? Apr 10, 2025 pm 02:24 PM

Redis memory fragmentation refers to the existence of small free areas in the allocated memory that cannot be reassigned. Coping strategies include: Restart Redis: completely clear the memory, but interrupt service. Optimize data structures: Use a structure that is more suitable for Redis to reduce the number of memory allocations and releases. Adjust configuration parameters: Use the policy to eliminate the least recently used key-value pairs. Use persistence mechanism: Back up data regularly and restart Redis to clean up fragments. Monitor memory usage: Discover problems in a timely manner and take measures.

How to implement redis counter How to implement redis counter Apr 10, 2025 pm 10:21 PM

Redis counter is a mechanism that uses Redis key-value pair storage to implement counting operations, including the following steps: creating counter keys, increasing counts, decreasing counts, resetting counts, and obtaining counts. The advantages of Redis counters include fast speed, high concurrency, durability and simplicity and ease of use. It can be used in scenarios such as user access counting, real-time metric tracking, game scores and rankings, and order processing counting.

See all articles