多数据库连接工具包,提供统一的接口支持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.9.tar.gz
(17.8 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.9.tar.gz.
File metadata
- Download URL: liwancai_pydblinks-1.0.9.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7444f0ec66c0e619ae83d3ae3752c57b80f73b4931afd2506c9cd91f59fab64a
|
|
| MD5 |
8bc9f599351f644283c3ff985a5d178d
|
|
| BLAKE2b-256 |
f4dde2c47b63053f7e151359c2744796ab010a208c4320af9f62496f21972d8d
|
File details
Details for the file liwancai_pydblinks-1.0.9-py3-none-any.whl.
File metadata
- Download URL: liwancai_pydblinks-1.0.9-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7885a196978bcde6f49c2071f67fbe89cf931b23df37e3ba5197b48fff242bc8
|
|
| MD5 |
d95bf80108b7baa960a806c86b8337d1
|
|
| BLAKE2b-256 |
0b0c8765d19cff428fdd45348d38ec517bc63329dc5525f888ca3d522233e4bd
|