DBGenie
0.0.1
DBGenie是一個Python軟件包,可在MongoDB,PostgreSQL和MySQL數據庫上自動化數據庫操作的類。該軟件包提供了易於使用的類,可封裝通用數據庫操作,從而使開發人員專注於構建其應用程序,而不是處理低級數據庫交互。
您可以使用PIP安裝DBGenie:
pip install dbgenie2支持多個數據庫:DBGenie對MongoDB,PostgreSQL和MySQL數據庫有支持,為跨不同數據庫系統的CRUD操作提供了一個統一的接口。
簡單而直觀的API:該軟件包提供了用於執行CRUD操作的直接API,使開發人員可以輕鬆地與數據庫進行交互,而無需編寫複雜的SQL查詢或MongoDB命令。
自動連接管理:DataBaseCrud處理數據庫連接管理,包括連接到數據庫,執行查詢和關閉連接,從而確保有效的資源使用情況並防止內存洩漏。
靈活和擴展的:該軟件包的設計為靈活和可擴展,使開發人員可以根據需要自定義和擴展其特定用例的功能。
DBGenie為每個受支持的數據庫系統提供單獨的類:
每個類都封裝了其各自數據庫系統的常見CRUD操作,包括:
開發人員可以實例化這些類,配置連接參數,並使用提供的方法無縫與其數據庫進行交互。
from dbgenie.mongodb.mongocrud import MongoDBCrud
# Connect to MongoDB
mongodb_crud = MongoDBCrud(uri= " mongodb://localhost:27017 " , database= " my_database " , collection= " my_collection " )
# Insert document
mongodb_crud.insert_document({ " name " : " John " , " age " : 30})
# Find document
document = mongodb_crud.find_document({ " name " : " John " })
print(document)
# Update document
mongodb_crud.update_document({ " name " : " John " }, { " age " : 35})
# Delete document
mongodb_crud.delete_document({ " name " : " John " })from dbgenie.postgresql.postgrescrud import PostgreSQLCrud
# Connect to PostgreSQL
postgresql_crud = PostgreSQLCrud(host= " localhost " , user= " postgres " , password= " password " , database= " my_database " )
# Create table
postgresql_crud.create_table( " my_table " , [ " id SERIAL PRIMARY KEY " , " name VARCHAR(255) " , " age INT " ])
# Insert record
postgresql_crud.insert_record( " my_table " , (1, " John " , 30))
# Read records
records = postgresql_crud.read_records( " my_table " )
print(records)
# Update record
postgresql_crud.update_record( " my_table " , { " age " : 35}, " name='John' " )
# Delete record
postgresql_crud.delete_record( " my_table " , " name='John' " )from dbgenie.mysql.mysqlcrud import MySQLCrud
# Connect to MySQL
mysql_crud = MySQLCrud(host= " localhost " , user= " root " , password= " password " , database= " my_database " )
# Create table
mysql_crud.create_table( " my_table " , [ " id INT AUTO_INCREMENT PRIMARY KEY " , " name VARCHAR(255) " , " age INT " ])
# Insert record
mysql_crud.insert_record( " my_table " , (1, " John " , 30))
# Read records
records = mysql_crud.read_records( " my_table " )
print(records)
# Update record
mysql_crud.update_record( " my_table " , { " age " : 35}, " name='John' " )
# Delete record
mysql_crud.delete_record( " my_table " , " name='John' " )歡迎對DBGenie的貢獻!如果您對新功能,改進或錯誤修復有想法,請隨時打開問題或提交拉動請求。有關更多信息,請參見貢獻指南。
DBGenie已獲得MIT許可證的許可。有關詳細信息,請參見許可證文件。