Skip to main content

多数据库连接工具包,提供统一的接口支持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) - 多表联合查询

设计特点

  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

Project details


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

liwancai_pydblinks-1.0.9-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page