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.1.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.1.1-py2.py3-none-any.whl (16.4 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: wkmysql-1.1.2.1.1.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.1.1.tar.gz
Algorithm Hash digest
SHA256 df553653959d56a332f51bd24458518df76e54a2f39d752445eb3d2fac7b960f
MD5 b0c694838c8cb7caeb24ac7c3d7f6192
BLAKE2b-256 4ed050c7039ae5ea2b6c84e96b8e63287fd00576709e698f37a2c23ef3a6500f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: WkMysql-1.1.2.1.1-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.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cb87e61f1aac5cb250a22c32b5617514e05f1d5f1f5195192e8bed3e6f13110e
MD5 dd51e457efc37495f08ab70d6186751e
BLAKE2b-256 0a482a0d038af50bfc0f163684dba5c7ea63b92ec1872a6181c9ec4219b2e2a7

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