A functional enhancement package that focus on crud based PyMySQL
Project description
PyMySQLDao
Introduce
PyMySQLDao是建立在PyMySQL上的功能增强库,方便用户进行CRUD;
在不影响任何代码的情况下,只需要简单几行代码,便可获得表的CRUD功能!
欢迎提出修改意见!🥳🥳🥳
Requirements
Install
(venv)$ pip install pymysql-dao
说明:如果上述的命令无法下载,请考虑使用下列命令:
pypi官方
$ pip install pymysql-dao --index-url https://pypi.org/simple/
清华源
$ pip install pymysql-dao --index-url https://pypi.tuna.tsinghua.edu.cn/simple/
Examples
1)使用pymysqldao进行CRUD
假设使用此SQL文件
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import pymysql
from pymysqldao import CRUDHelper
conn = pymysql.connect(
host='localhost',
user='root',
password='',
database='python_example',
cursorclass=pymysql.cursors.DictCursor
)
class ClassDao(CRUDHelper):
def __init__(self):
super().__init__(connection=conn, table_name="class", size=500)
if __name__ == '__main__':
# print(ClassDao.__mro__)
dao = ClassDao()
# select * from class limit 20
dao.select_list()
# select * from class limit 2
dao.select_list(2)
# select * from class where class_name='火箭班' limit 20
dao.select_by_field("class_name", "火箭班")
# select * from class where class_name='骏马班' limit 10
dao.select_by_field("class_name", "骏马班", size=10)
# select * from class where id=1
dao.select_by_id(1)
# select * from class where id in (1, 2, 3)
dao.select_by_id_list([1, 2, 3])
# insert into class("class_name") values("少年班")
dao.insert_one({"class_name": "少年班"})
# update by id
result = dao.select_by_field("class_name", "少年班")
result[0]["class_name"] = "少年班修改"
dao.update_by_id(result[0])
# delete by id
dao.delete_by_id(result[0]["id"])
2)使用自己定义的log格式
import sys
import logging
import pymysql
from pymysqldao import CRUDHelper, LOGGER
LOGGER.setLevel(logging.DEBUG)
LOGGER.addHandler(logging.StreamHandler(sys.stderr))
conn = pymysql.connect(
host='localhost',
user='root',
password='',
database='python_example',
cursorclass=pymysql.cursors.DictCursor
)
class ClassDao(CRUDHelper):
def __init__(self):
super().__init__(connection=conn, table_name="class", size=500, use_own_log_config=True)
if __name__ == '__main__':
# print(ClassDao.__mro__)
dao = ClassDao()
# select * from class limit 20
dao.select_list()
# select * from class limit 2
dao.select_list(2)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pymysql_dao-0.0.10.tar.gz
(9.3 kB
view details)
Built Distribution
File details
Details for the file pymysql_dao-0.0.10.tar.gz
.
File metadata
- Download URL: pymysql_dao-0.0.10.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6db2d3bf4b842ed2e2c798ced6fd8ed2f1b0465dca68c73095ef9243c6755448 |
|
MD5 | c901b7a6d221c8c3cbde1c0eb041fc0e |
|
BLAKE2b-256 | 64d3a06f7613ddcc49622279ced8e0ddb5e30ec5529c9b4338d7c70b28763276 |
File details
Details for the file pymysql_dao-0.0.10-py3-none-any.whl
.
File metadata
- Download URL: pymysql_dao-0.0.10-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | caab076c5622fda245cddc3710b11c66c4f4bbb078cef970a6f5ad235e559c96 |
|
MD5 | 610c60a2da90515a8d38050238d14e10 |
|
BLAKE2b-256 | 766e313577b679fca752d2971988d37d4415b73472e99437459a6555484df1c1 |