database-smartools
介绍
一个功能全面的数据库操作工具包,提供统一接口支持多种数据库系统,简化数据库连接、查询与管理操作。支持连接池管理、事务处理和跨数据库兼容功能,适用于需要与多数据库交互的Python项目。
软件架构
- 核心模块:
database/db_handler.py:数据库连接管理核心类database/*_extend.py:各数据库类型的扩展实现(MySQL、Oracle、PostgreSQL等)utils/:配置解析、日志记录等辅助工具
- 技术栈:Python 3.11+、SQLAlchemy、DBUtils连接池
支持数据库类型
- MySQL
- Oracle
- PostgreSQL
- 达梦数据库(Dameng)
- OceanBase
安装教程
pip install database-smartools
使用说明
# 基本使用示例
from database_smartools.database import db_handler as dh
from database_smartools.utils import logger, output
import pandas as pd
import traceback
if args["db_key"] not in dh.POOL_MAP.keys():
dh.get_pool_by_key(args["db_key"])
pool_map = dh.POOL_MAP[args["db_key"]]
params = {
"key": "value"
}
conn_map, message = dh.get_conn_map(pool_map)
if not conn_map:
result = False
return output.OutputUtil.map(result=result, message=message)
try:
conn = conn_map["conn"]
# conn_map["db_type"] = "oceanbase"
# print(conn_map)
# 日期遍历
result = True
logger.info("开始执行,执行参数:")
logger.info(params)
df, message = dh.select_by_map(conn_map, "select 'database_smartools' as software from dual", params)
df = pd.DataFrame(df["data"])
if not r:
result = False
except Exception as e:
conn.rollback() # 回滚事务
# 获取完整堆栈的错误信息
message = f"接口执行失败!\n完整错误堆栈信息:\n{traceback.format_exc()}"
logger.error(message)
result = False
finally:
conn.commit()
dh.close_conn(pool_map, conn_map)
return output.OutputUtil.map(result=result, message=message)
Debug示例
# 初始化数据库连接
from functions import t_r_299_result_n
from database_smartools.utils import debug
if __name__ == "__main__":
params = {
"db_key": "GB_YFDW_DW",
"p_jgdm": "70380000",
"p_file_date": "20240101",
"ind_type": "D",
"p_data_guid": "test_cqb",
"p_fund_type": "08",
"p_fund_category": "01",
"p_item_table": "",
"p_fdate": "20240101"
}
debug.debug_script(t_r_299_result_n.t_r_299_result_n, params, 'dev')
项目依赖
- SQLAlchemy 2.0.40+
- DBUtils 3.0.0+
- 各数据库驱动(mysql-connector-python、oracledb等)
许可证
MIT License
Metadata
Release files for database-smartools 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| database_smartools-0.0.4.tar.gz | 26.2 kB | Without provenance | Details for database_smartools-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| database_smartools-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for database_smartools-0.0.4-py3-none-any.whl |
Total release size: 62.5 kB
Release files / database_smartools-0.0.4.tar.gz
| Download URL | database_smartools-0.0.4.tar.gz |
|---|---|
| Size | 26.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
830e5d79ca2ef722c5119d0798f99d02997f425b71201ce9133cf739c535e41c
|
|
BLAKE2b-256 checksum How to use checksums |
70c2e1128ade4e77e6d4a545e5f88c29f93b3c6e811b5dc4cece6b41233afcb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / database_smartools-0.0.4-py3-none-any.whl
| Download URL | database_smartools-0.0.4-py3-none-any.whl |
|---|---|
| Size | 36.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33515f258972cc91754c8b14bc276fa7165926a53a278a64e8fa31085fb22c22
|
|
BLAKE2b-256 checksum How to use checksums |
6638a4b59185a006b6c27f29ab3482ac2c5e0262616638be83fd3931f72f336d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for database-smartools 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.