一个MySQL简单操作方式
Project description
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}
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
PureMySQL-0.0.8.tar.gz
(6.3 kB
view details)
Built Distributions
PureMySQL-0.0.8-py3.7.egg
(15.4 kB
view details)
File details
Details for the file PureMySQL-0.0.8.tar.gz
.
File metadata
- Download URL: PureMySQL-0.0.8.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9751777c25a8905951e0d39c3c23fb374e60e0a7881681c0415cc3e1aed6ea08 |
|
MD5 | ae934aa184910e91cb5cc8c4f6131eb7 |
|
BLAKE2b-256 | 87ad6f6e06138a08842dc8340f5d2b27363c3840e72e8d8393d68ebb99c6b316 |
File details
Details for the file PureMySQL-0.0.8-py3.7.egg
.
File metadata
- Download URL: PureMySQL-0.0.8-py3.7.egg
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0759326cd7c5907ce9f0e902883707278cd2966221930abcf481685bbf06f9fd |
|
MD5 | 65bc22c4a20f4350735d148f15da2674 |
|
BLAKE2b-256 | 14b5a78b3e7a3e38a6e6a6881154bfd6c111db8083131e5b6e0de50ab54b601f |
File details
Details for the file PureMySQL-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: PureMySQL-0.0.8-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 291cdc4606dc987430c007178f1a4412bb8bf60c0b94a73c90045c5c32f09041 |
|
MD5 | 2568d23c7be8ddca04fbaced7d1f7ea3 |
|
BLAKE2b-256 | 3f6287aaf79e8fa46c4194106a8f75534a6b2f3d038a72653bbeff6b146930d0 |