贝利信息

HadiDB:Python 中的轻量级、可水平扩展的数据库

日期:2024-12-25 00:00 / 作者:霞舞

HadiDB:轻量级、高水平可扩展的Python数据库

HadiDB (hadidb) 是一个用Python编写的轻量级数据库,具备高度水平的可扩展性。

安装HadiDB

使用pip安装:

pip install hadidb

用户管理

创建用户:createuser() 方法创建一个新用户。authentication() 方法验证用户身份。

from hadidb.operation import user

user_obj = user("admin", "admin")
user_obj.createuser()  # 创建用户
user_obj.authentication()  # 验证用户

返回结果示例:

{'status': 200, 'message': 'database user created'}

数据库、集合和模式创建

以下代码片段展示了如何设置用户凭据、数据库集合架构,以及如何插入数据。

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)

数据操作

data = {
    "username": "hadidb",
    "password": "12345",
    "cnic": "123232442",
    "picture": "user/my/hadidb.jpg",
    "bio": "hadidb is the best ;)"
}
result = db.insert(data)
print(result)

返回结果示例:

{
'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
     }
}
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)

数据库和集合管理

项目链接

这个版本对原文进行了重新组织和润色,使其更清晰易读,并对代码部分进行了格式化,使其更易于理解。 所有图片链接都保留了。