PureMySQL
一个MySQL简单操作方式
pip install PureMySQL
代码示例
# -*- coding: utf-8 -*-
from puremysql import PureMysql
db_config = {
"database": "mydata",
"user": "root",
"password": "123456",
"host": "127.0.0.1",
"port": 3306,
}
pure_mysql = PureMysql(**db_config)
# 或者
# url = "mysql://root:123456@127.0.0.1:3306/mydata"
# pure_mysql = PureMysql(db_url=url)
student = pure_mysql.table("student")
# 插入数据
def test_insert():
data = {
"name": "Tom",
"age": 25
}
count = student.insert(data)
print(count) # 1
data = [
{
"name": "Tom",
"age": 26,
},
{
"name": "Jack",
"age": 27,
}
]
count = student.insert(data)
print(count) # 2
# 删除数据
def test_delete():
ret = student.delete("id=13")
print(ret) # 1
ret = student.delete_by_id(12)
print(ret) # 1
# 更新数据
def test_update():
data = {
"name": "Tom"
}
ret = student.update(data, "name='Tom'")
print(ret) # 1
ret = student.update_by_id(data, 1)
print(ret) # 1
# 查询数据
def test_select():
ret = student.select(["name", "age"], "id=1")
print(ret)
# [{"name": "Tom", "age": 25}]
ret = student.select("name, age", "id=1")
print(ret)
# [{"name": "Tom", "age": 25}]
ret = student.select_one(["name", "age"], "id=1")
print(ret)
# {"name": "Tom", "age": 25}
ret = student.select_by_id("name, age", 2007)
print(ret)
# {"name": "Tom", "age": 25}
Release files for PureMySQL 0.0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| PureMySQL-0.0.10.tar.gz | 6.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| PureMySQL-0.0.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.9 kB
Release files / PureMySQL-0.0.10.tar.gz
| Download URL | PureMySQL-0.0.10.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63d4036649ee9cd034b800eefe068bae01a3fa746f165ec996fe16d6b6aea524
|
|
BLAKE2b-256 checksum How to use checksums |
c7d531a818b588ec69651ec2fa3959b2bf94c1c2d600f6c26c2dc72d6e75acda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0
|
Release files / PureMySQL-0.0.10-py3-none-any.whl
| Download URL | PureMySQL-0.0.10-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d73d4b3474a9c4fbafd9b1421c2ff76a071b295c7110d806aeece80db7bfc986
|
|
BLAKE2b-256 checksum How to use checksums |
e61c3c8ae45a79298a1a76e2973eea5787e16d7e45cc17f117b35232dfc163f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0
|