说明
安装:
pip install mysql-lingling
1、作用
mysql 模块的再包装,并支持 with语法。
将使用简化抽象为:
- 连接数据库;
- 执行sql语句并获得返回结果;
- 关闭数据库(使用with的时候可以省略);
2、示例
示例1(with语法)
# 连接数据库
with MySQLTool(user=user, password=pw, database=database) as m2:
# 执行sql并获得返回结果
result2 = m2.run_sql([
['insert person(name, age) values ("李四", 20), ("王五", 30)'],
['select * from person']
])
# 打印结果
print(result2)
示例2(普通语法,建议使用专有语法,这里是通用语法示例)
m = MySQLTool()
# 查看mysql容器内 ip,参考这个链接:https://blog.csdn.net/CSDN_duomaomao/article/details/75638544
m.connect(user=user,
password=pw,
# host=ip,
database=database)
result = m.run_sql([
['insert person(name,age) values (%s, %s)', ['六六六', 666]],
['select * from person']
])
print(result)
m.close()
示例3(同时插入多行数据)
with MySQLTool(user=user, password=pw, database=database, host=host) as m2:
# 执行sql并获得返回结果
result2 = m2.insert_more_rows(
'INSERT INTO key_value (k, val, creator_id, user_id, status) values (%s, %s, %s, %s, %s)',
[
('c', 'AAA', 1, '1', 0),
('d', 'BBB', 1, '1', 0)
]
)
if result2 is not False:
print('success')
else:
print('error!')
Release files for mysql-lingling 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mysql_lingling-0.0.8.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mysql_lingling-0.0.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.4 kB
Release files / mysql_lingling-0.0.8.tar.gz
| Download URL | mysql_lingling-0.0.8.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48d793e3dff1f13b82cac994ed0af98a8f36538522606c79522cc141bbf04b03
|
|
BLAKE2b-256 checksum How to use checksums |
56cf18b0394459f4985a76fd31c52eae36dd8bca153c4ddd33665f7d66557d42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Release files / mysql_lingling-0.0.8-py3-none-any.whl
| Download URL | mysql_lingling-0.0.8-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c4eb28234815b41c7581e9d3650ac3d9d317a749214fff6ad59c53f53df1dc63
|
|
BLAKE2b-256 checksum How to use checksums |
5e8da89c466fac54f3d8ca07d0eac492ccb3016b4c4de5efe637a18c33595632
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|