# PyMysqlTools
PyMysqlTools 是一个使用封装好的函数替代SQL语句来操作mysql的工具库
**环境配置**
PyMysqlTools 目前支持 Python3.6+ 且 MySQL5.6+ 版本
### 快速开始
- 下载本项目
```bash
pip install PyMysqlTools
```
- 导入本项目到您的代码
```python
import PyMysqlTools
```
1. 建立连接
```python
import PyMysqlTools
# 可以使用下面的示例代码直接获得一个mysql数据库的连接
mysql = PyMysqlTools.connect(
database='db_test',
username='root',
password='123456'
)
print(mysql) # <PyMysqlTools.main.Connect object>
```
2. 简单使用
- 添加数据
```python
# 准备待添加的数据, key=字段名, value=字段值
data = {
'username': 'abc',
'password': 'abc123'
}
# 添加数据到数据表
mysql.insert_one('tb_test', data)
```
- 删除数据
```python
# 根据id删除数据
mysql.delete_by_id('tb_test', 2)
```
- 修改数据
```python
# 准备待修改的数据, key=字段名, value=字段值
data = {
'username': 'abc',
'password': 'abc123'
}
# 修改数据表中的数据
mysql.update_by_id('tb_test', data, 3)
```
- 查询数据
```python
# 查询全表数据并遍历输出
for row in mysql.find_all('tb_test'):
print(row)
```
### 关于
如果您在使用时遇到了意料之外的结果,请[提交Issue](https://gitee.com/uraurara/PyMysqlTools/issues/new?issue%5Bassignee_id%5D=0&issue%5Bmilestone_id%5D=0)帮助我们改进此项目。
### Thanks
本项目在开发中使用了以下Python库
- [PyMySQL](https://gitee.com/src-openeuler/python-PyMySQL)
- [DBUtils](https://github.com/WebwareForPython/DBUtils)
Raw data
{
"_id": null,
"home_page": "https://gitee.com/uraurara/PyMysqlTools",
"name": "PyMysqlTools",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8.10",
"maintainer_email": "",
"keywords": "mysql,client,mysqluitls,PyMysqlTools",
"author": "ulala",
"author_email": "2713389652@qq.com",
"download_url": "https://files.pythonhosted.org/packages/65/cb/062047e0ca7e1cdb8b4b407e550a9a779487280ac8badbfac99c63cae0ce/PyMysqlTools-0.6.6.tar.gz",
"platform": null,
"description": "\r\n# PyMysqlTools\r\n\r\n\r\nPyMysqlTools \u662f\u4e00\u4e2a\u4f7f\u7528\u5c01\u88c5\u597d\u7684\u51fd\u6570\u66ff\u4ee3SQL\u8bed\u53e5\u6765\u64cd\u4f5cmysql\u7684\u5de5\u5177\u5e93\r\n\r\n\r\n\r\n**\u73af\u5883\u914d\u7f6e**\r\n\r\nPyMysqlTools \u76ee\u524d\u652f\u6301 Python3.6+ \u4e14 MySQL5.6+ \u7248\u672c\r\n\r\n\r\n\r\n### \u5feb\u901f\u5f00\u59cb\r\n\r\n- \u4e0b\u8f7d\u672c\u9879\u76ee\r\n\r\n ```bash\r\n pip install PyMysqlTools\r\n ```\r\n\r\n- \u5bfc\u5165\u672c\u9879\u76ee\u5230\u60a8\u7684\u4ee3\u7801\r\n\r\n ```python\r\n import PyMysqlTools\r\n ```\r\n\r\n \r\n\r\n1. \u5efa\u7acb\u8fde\u63a5\r\n\r\n ```python\r\n import PyMysqlTools\r\n \r\n # \u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u793a\u4f8b\u4ee3\u7801\u76f4\u63a5\u83b7\u5f97\u4e00\u4e2amysql\u6570\u636e\u5e93\u7684\u8fde\u63a5\r\n mysql = PyMysqlTools.connect(\r\n database='db_test',\r\n username='root',\r\n password='123456'\r\n )\r\n print(mysql) # <PyMysqlTools.main.Connect object>\r\n ```\r\n\r\n2. \u7b80\u5355\u4f7f\u7528\r\n\r\n - \u6dfb\u52a0\u6570\u636e\r\n\r\n ```python\r\n # \u51c6\u5907\u5f85\u6dfb\u52a0\u7684\u6570\u636e, key=\u5b57\u6bb5\u540d, value=\u5b57\u6bb5\u503c\r\n data = {\r\n 'username': 'abc',\r\n 'password': 'abc123'\r\n }\r\n \r\n # \u6dfb\u52a0\u6570\u636e\u5230\u6570\u636e\u8868\r\n mysql.insert_one('tb_test', data)\r\n ```\r\n\r\n \r\n\r\n - \u5220\u9664\u6570\u636e\r\n\r\n ```python\r\n # \u6839\u636eid\u5220\u9664\u6570\u636e\r\n mysql.delete_by_id('tb_test', 2)\r\n ```\r\n\r\n \r\n\r\n - \u4fee\u6539\u6570\u636e\r\n\r\n ```python\r\n # \u51c6\u5907\u5f85\u4fee\u6539\u7684\u6570\u636e, key=\u5b57\u6bb5\u540d, value=\u5b57\u6bb5\u503c\r\n data = {\r\n 'username': 'abc',\r\n 'password': 'abc123'\r\n }\r\n \r\n # \u4fee\u6539\u6570\u636e\u8868\u4e2d\u7684\u6570\u636e\r\n mysql.update_by_id('tb_test', data, 3)\r\n ```\r\n\r\n \r\n\r\n - \u67e5\u8be2\u6570\u636e\r\n\r\n ```python\r\n # \u67e5\u8be2\u5168\u8868\u6570\u636e\u5e76\u904d\u5386\u8f93\u51fa\r\n for row in mysql.find_all('tb_test'):\r\n print(row)\r\n ```\r\n\r\n\r\n\r\n\r\n### \u5173\u4e8e\r\n\r\n\u5982\u679c\u60a8\u5728\u4f7f\u7528\u65f6\u9047\u5230\u4e86\u610f\u6599\u4e4b\u5916\u7684\u7ed3\u679c\uff0c\u8bf7[\u63d0\u4ea4Issue](https://gitee.com/uraurara/PyMysqlTools/issues/new?issue%5Bassignee_id%5D=0&issue%5Bmilestone_id%5D=0)\u5e2e\u52a9\u6211\u4eec\u6539\u8fdb\u6b64\u9879\u76ee\u3002\r\n\r\n\r\n\r\n### Thanks\r\n\r\n\u672c\u9879\u76ee\u5728\u5f00\u53d1\u4e2d\u4f7f\u7528\u4e86\u4ee5\u4e0bPython\u5e93\r\n- [PyMySQL](https://gitee.com/src-openeuler/python-PyMySQL)\r\n- [DBUtils](https://github.com/WebwareForPython/DBUtils)\r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library that makes MySQL operation more convenient.",
"version": "0.6.6",
"project_urls": {
"Homepage": "https://gitee.com/uraurara/PyMysqlTools"
},
"split_keywords": [
"mysql",
"client",
"mysqluitls",
"pymysqltools"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0f17f4ff0e380d212ea2107756b52c5efed786cd18f4f9b8551363e1e0461ede",
"md5": "d2ad52b2af60aa77770026f509784a82",
"sha256": "1678436f503a139b3eee156135abeef707c439cd49a5209c91ba1b3cf0787d35"
},
"downloads": -1,
"filename": "PyMysqlTools-0.6.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d2ad52b2af60aa77770026f509784a82",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.10",
"size": 12111,
"upload_time": "2023-12-11T07:32:23",
"upload_time_iso_8601": "2023-12-11T07:32:23.809460Z",
"url": "https://files.pythonhosted.org/packages/0f/17/f4ff0e380d212ea2107756b52c5efed786cd18f4f9b8551363e1e0461ede/PyMysqlTools-0.6.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "65cb062047e0ca7e1cdb8b4b407e550a9a779487280ac8badbfac99c63cae0ce",
"md5": "8646daf749be2ae28933b0e4824f6f75",
"sha256": "4652d236b158da9330797a6421b7f216f2d7fe9cbe9098350160886ceeb27452"
},
"downloads": -1,
"filename": "PyMysqlTools-0.6.6.tar.gz",
"has_sig": false,
"md5_digest": "8646daf749be2ae28933b0e4824f6f75",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.10",
"size": 11423,
"upload_time": "2023-12-11T07:32:25",
"upload_time_iso_8601": "2023-12-11T07:32:25.934177Z",
"url": "https://files.pythonhosted.org/packages/65/cb/062047e0ca7e1cdb8b4b407e550a9a779487280ac8badbfac99c63cae0ce/PyMysqlTools-0.6.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-11 07:32:25",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "pymysqltools"
}