多数据库连接工具包,提供统一的接口支持MySQL、SQLite、Redis、DuckDB等多种数据库
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
liwancai_pydblinks-1.0.10.tar.gz
(17.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file liwancai_pydblinks-1.0.10.tar.gz.
File metadata
- Download URL: liwancai_pydblinks-1.0.10.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f18c284c2bc7aac3754295c5ef3953c31d5f59b54faa2732d2f06d6b65d07059
|
|
| MD5 |
0bd514c0f01039a196e9a3194ecc55b2
|
|
| BLAKE2b-256 |
486304eceeb43a1857f88841b96e033c72f58934563e92ac55786c0ba3ddf218
|
File details
Details for the file liwancai_pydblinks-1.0.10-py3-none-any.whl.
File metadata
- Download URL: liwancai_pydblinks-1.0.10-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0875013edc8b064860fa38f94a527289ed221bafe9cd4de1c9f18a088526d197
|
|
| MD5 |
56c84cb056dd8de718e1ac0ac688e875
|
|
| BLAKE2b-256 |
2fd828a18244b0a6b9832641141d5c964085735ff28a64c56c9d1d43dd81cb5e
|