PyDBLinks
多数据库连接工具包,提供统一的接口支持MySQL、SQLite、Redis、DuckDB等多种数据库连接。
注意: 包在PyPI上的名称是 liwancai-PyDBLinks,但导入时使用 PyDBLinks
安装
pip install liwancai-PyDBLinks
使用
# 导入整个包的所有功能
from PyDBLinks import *
# 使用功能示例
# 初始化MySQL数据库连接
mysql_db = InitSqlDB(config, "mysql_config")
# 初始化SQLite数据库连接
sqlite_db = InitLiteDB(config, "sqlite_config")
# 初始化Redis数据库连接
redis_db = InitRdStDB(config, "redis_db", "redis_config")
# 初始化DuckDB数据库连接
duckdb_db = InitDuckDB(config, "duckdb_config")
其他导入方式
# 导入特定模块
from PyDBLinks import DBMySQL
mysql_db = DBMySQL.InitSqlDB(config, "mysql_config")
# 导入特定函数
from PyDBLinks.DBMySQL import MySqlDB
mysql_db = MySqlDB(config)
功能模块
1. MySQL数据库连接 (DBMySQL)
InitSqlDB(config, KeyName="")- 初始化MySQL数据库连接MySqlDB(config)- MySQL数据库连接类LinkSelect(CDs, CD, link, bracket)- 条件连接工具函数
2. SQLite数据库连接 (DBSqlLite)
InitLiteDB(config, KeyName="")- 初始化SQLite数据库连接SqliteDB(SQLconfig, path)- SQLite数据库连接类
3. Redis数据库连接 (DBRedist)
InitRdStDB(config, name, KeyName="", dbnum=0)- 初始化Redis数据库连接RdStConfig(keyname, filename, path)- 读取Redis配置RdSt(name, RDLINKCFG, dbnum)- Redis数据库连接类
4. DuckDB数据库连接 (DBDuck)
InitDuckDB(config, KeyName="", db_path, db_name, read_only)- 初始化DuckDB数据库连接DuckDB(config)- DuckDB数据库连接类
5. DDL和主键配置管理 (DDLMKey)
GetTomlDDLMkey(FileName, FilePath, COMMENT)- 读取DDL和主键配置信息
6. 工具函数 (Tools)
LinkSelect(CDs, CD, link, bracket)- 条件连接工具DBTblFileds(dbname, tblname, fileds)- 数据库表字段格式化LinkDBWith(dbA, dbB, tblA, tblB, CDFileds, method, linkwith)- 多表连接MultiLinkData(dbnames, GDB, tblnames, Gtbl, fileds, CDFiled, method, whereCD, limitCD)- 多表联合查询
设计特点
- 统一接口: 不同数据库使用相似的API设计,便于迁移
- 配置驱动: 支持通过配置文件管理数据库连接参数
- SSH隧道: MySQL支持SSH隧道连接远程数据库
- 错误处理: 完善的异常处理和日志记录
- 性能优化: 支持连接池和批量操作
配置示例
MySQL配置
[mysql_config]
host = "localhost"
user = "root"
password = "password"
dbname = "mydb"
charset = "utf8"
BySSH = false
sshhost = "192.168.1.100"
sshport = 22
sshuser = "admin"
sshpassword = "123456"
SQLite配置
[sqlite_config]
path = "./Datas/"
dbname = "mydb"
Redis配置
[redis_config]
host = "localhost"
port = 6379
password = ""
db = 0
DuckDB配置
[duckdb_config]
db_path = "./Datas/duckdb/"
db_name = "mydb.db"
memory_limit = "1GB"
threads = 4
许可证
MIT License
Metadata
Release files for liwancai-PyDBLinks 1.0.10
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 |
|---|---|---|---|---|
| liwancai_pydblinks-1.0.10.tar.gz | 17.7 kB | Without provenance | Details for liwancai_pydblinks-1.0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| liwancai_pydblinks-1.0.10-py3-none-any.whl | Python 3 | none | any | Details for liwancai_pydblinks-1.0.10-py3-none-any.whl |
Total release size: 39.2 kB
Release files / liwancai_pydblinks-1.0.10.tar.gz
| Download URL | liwancai_pydblinks-1.0.10.tar.gz |
|---|---|
| Size | 17.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f18c284c2bc7aac3754295c5ef3953c31d5f59b54faa2732d2f06d6b65d07059
|
|
BLAKE2b-256 checksum How to use checksums |
486304eceeb43a1857f88841b96e033c72f58934563e92ac55786c0ba3ddf218
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / liwancai_pydblinks-1.0.10-py3-none-any.whl
| Download URL | liwancai_pydblinks-1.0.10-py3-none-any.whl |
|---|---|
| Size | 21.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0875013edc8b064860fa38f94a527289ed221bafe9cd4de1c9f18a088526d197
|
|
BLAKE2b-256 checksum How to use checksums |
2fd828a18244b0a6b9832641141d5c964085735ff28a64c56c9d1d43dd81cb5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for liwancai-PyDBLinks 1.0.10
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.