HadiDB:輕量級、高水平可擴展的Python數(shù)據(jù)庫
HadiDB (hadidb) 是一個用Python編寫的輕量級數(shù)據(jù)庫,具備高度水平的可擴展性。
安裝HadiDB
使用pip安裝:
立即學習“Python免費學習筆記(深入)”;
pip install hadidb
用戶管理
創(chuàng)建用戶:createuser() 方法創(chuàng)建一個新用戶。authentication() 方法驗證用戶身份。
from hadidb.operation import user user_obj = user("admin", "admin") user_obj.createuser() # 創(chuàng)建用戶 user_obj.authentication() # 驗證用戶
返回結(jié)果示例:
{'status': 200, 'message': 'database user created'}
數(shù)據(jù)庫、集合和模式創(chuàng)建
以下代碼片段展示了如何設置用戶憑據(jù)、數(shù)據(jù)庫集合架構(gòu),以及如何插入數(shù)據(jù)。
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)
數(shù)據(jù)操作
- 插入數(shù)據(jù): db.insert(data) 方法插入數(shù)據(jù)。
data = { "username": "hadidb", "password": "12345", "cnic": "123232442", "picture": "user/my/hadidb.jpg", "bio": "hadidb is the best ;)" } result = db.insert(data) print(result)
返回結(jié)果示例:
{ '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 } }
- 更新數(shù)據(jù): db.update(1, update_data) 方法更新數(shù)據(jù)。
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)
-
按ID獲取數(shù)據(jù): db.getbyid(1) 方法按ID獲取數(shù)據(jù)。
-
獲取所有數(shù)據(jù): db.getall() 方法獲取所有數(shù)據(jù)。
-
按鍵獲取數(shù)據(jù): db.getbykey() 和 db.getbykeys() 方法按鍵獲取數(shù)據(jù)。
-
計數(shù): db.count() 方法統(tǒng)計數(shù)據(jù)數(shù)量。db.getbykeycount() 方法統(tǒng)計指定鍵值對匹配的數(shù)據(jù)數(shù)量。
-
刪除數(shù)據(jù): db.delete(1) 方法刪除數(shù)據(jù)。
數(shù)據(jù)庫和集合管理
-
獲取所有數(shù)據(jù)庫: configuration().get_database() 方法獲取所有數(shù)據(jù)庫。
-
獲取所有集合: configuration(database).get_collection() 方法獲取指定數(shù)據(jù)庫的所有集合。
-
獲取模式: configuration(database, collection).get_schema() 方法獲取指定集合的模式。
-
刪除集合: databasedeletionservice().deletecollection() 方法刪除集合。
-
刪除數(shù)據(jù)庫: databasedeletionservice().deleteDatabase() 方法刪除數(shù)據(jù)庫。
項目鏈接
- gitHub: https://www.php.cn/link/e8630344970962450dbedfcd4cc6d718
- 網(wǎng)站: https://www.php.cn/link/2c6037040bf5058a44be4c0397611909
- 開發(fā)者: 莫明·伊克巴爾
這個版本對原文進行了重新組織和潤色,使其更清晰易讀,并對代碼部分進行了格式化,使其更易于理解。 所有圖片鏈接都保留了。