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.1.tar.gz (21.6 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.1-py2.py3-none-any.whl (15.8 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: wkmysql-1.1.2.1.tar.gz
  • Upload date:
  • Size: 21.6 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.1.tar.gz
Algorithm Hash digest
SHA256 ec39a0fd096b9a9f751c3dccfecd15543d605c2cb3bdabe0d4cb316c21307ed9
MD5 8ebaee3bb15d66a3334151cc16bde470
BLAKE2b-256 a15b9593a10243b2884642e350fea185015d00dcdcfe8e7c4f6ca3c6854709ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: WkMysql-1.1.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.8 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.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 994a5ef39e157f48db59f2c0de2d22f3c4c3af7a5b673113499a434471a62d5f
MD5 8fb9ec809a2540eb111adedcae04410b
BLAKE2b-256 f0fce5a1c849b3e128b04da5190a8bfaaed08fa71d993a726ef314ed2385bef6

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