Skip to main content

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) - 多表联合查询

设计特点

  1. 统一接口: 不同数据库使用相似的API设计,便于迁移
  2. 配置驱动: 支持通过配置文件管理数据库连接参数
  3. SSH隧道: MySQL支持SSH隧道连接远程数据库
  4. 错误处理: 完善的异常处理和日志记录
  5. 性能优化: 支持连接池和批量操作

配置示例

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)

Source distribution for liwancai-PyDBLinks 1.0.10
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)

Table of built distributions (wheels) for liwancai-PyDBLinks 1.0.10
File Interpreter ABI Platform Actions
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

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.

Release history Release notifications | RSS feed

This release

1.0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page