Skip to main content

The secondary encapsulation of pymysql provides a more user-friendly interface and thread pool, and will support SQLite in the future.

Project description

WkMysql

WkMysql 是一个用于简化与 MySQL 数据库交互的 Python 模块,专为单线程应用设计,适合短时间内快速连接 MySQL 数据库。通过此模块,您可以轻松执行数据库的创建、查询、插入、更新和删除等操作。

特点

  • 易用性: 提供简单明了的 API,便于用户进行数据库操作。
  • 持久连接: 自动测试并保持数据库连接的活跃性,减少频繁连接的开销。
  • 线程安全: 使用线程锁确保在多线程环境中安全地操作数据库。
  • 详细日志: 提供操作成功与失败的记录,便于调试和维护。
  • 支持事务: 执行插入、更新及删除操作时支持事务,确保数据一致性。

依赖

在使用 WkMysql 之前,请确保安装 pymysql 库:

pip install pymysql

安装

pip install WkMysql

使用方法

1. 初始化

from WkMysql import WkMysql

db = WkMysql(
    host='localhost',
    user='root',
    password='123456',
    database='myproject'
)

2. 设置操作表

设置当前操作的表:

db.set_table('test_table')

3. 创建表

创建新表:

db.create_table({'id': 'INT PRIMARY KEY', 'name': 'VARCHAR(50)'})

4. 插入数据

插入一行数据:

result, insert_id = db.insert_row({'id': 1, 'name': 'wangkang'})

5. 查询数据

查询表中的所有数据:

all_data = db.select_all()

6. 更新数据

更新已有数据:

db.update({'id': 1}, {'name': 'new_name'})

7. 删除数据

删除特定行:

db.delete_row({'id': 1})

8. 关闭连接

在程序结束时关闭数据库连接:

db.close()

示例

以下是一个完整的示例,演示如何使用 WkMysql 包进行常见的数据库操作:

from WkMysql import WkMysql

db = WkMysql(
    host='localhost',
    user='root',
    password='123456',
    database='myproject'
)

db.set_table('test_table')
db.create_table({'id': 'INT PRIMARY KEY', 'name': 'VARCHAR(50)'})
db.insert_row({'id': 1, 'name': 'wangkang'})
results = db.select_all()
print(results)
db.update({'id': 1}, {'name': 'new_name'})
db.delete_row({'id': 1})

项目地址

项目源代码及文档请访问:WkMysql 项目

许可证

本项目遵循 GPL2.0 许可证。请查看 LICENSE 文件以获取更多信息。


感谢您使用 WkMysql!如有任何问题或建议,请随时联系。

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

wkmysql-1.1.2.2.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

WkMysql-1.1.2.2-py2.py3-none-any.whl (16.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file wkmysql-1.1.2.2.tar.gz.

File metadata

  • Download URL: wkmysql-1.1.2.2.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.13

File hashes

Hashes for wkmysql-1.1.2.2.tar.gz
Algorithm Hash digest
SHA256 8e98afdff21f1d1681c297548b26b25c4467f69b292e1dec4fca0159fcd798cc
MD5 894bed6f5e3a15f9e658ee78f26d1d7c
BLAKE2b-256 8e4f78330ab8d01d3d63efeef956abb7ee85d0927634f4cb4a5c2278067eba4b

See more details on using hashes here.

File details

Details for the file WkMysql-1.1.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: WkMysql-1.1.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.13

File hashes

Hashes for WkMysql-1.1.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 854b02a81dbee220a0e644e2238ba793bc3b2b5a7cb1975a8d5622ed75278335
MD5 c0d08e2a76b323f9c952745d807ef7ec
BLAKE2b-256 79c289c30efcc109e313b07a7f0af0f042d740b00d7275106050cfe3dff7c760

See more details on using hashes here.

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