Skip to main content

PyMySQLDao

Introduce

PyMySQLDao是建立在PyMySQL上的功能增强库,方便用户进行CRUD;

在不影响任何代码的情况下,只需要简单几行代码,便可获得表的CRUD功能!

欢迎提出修改意见!🥳🥳🥳

Requirements

PyMySQL

pydantic

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)

Metadata

Release files for pymysql-dao 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymysql-dao 0.0.11
File Size Uploaded
pymysql_dao-0.0.11.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymysql-dao 0.0.11
File Interpreter ABI Platform
pymysql_dao-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 25.5 kB

Release files / pymysql_dao-0.0.11.tar.gz

Download URL pymysql_dao-0.0.11.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1eb466f544128fcb70e4afc71240548f91c84b5490c909ce6706726a20db0832
BLAKE2b-256 checksum
How to use checksums
d730f68acf3240e310876be747c56bfaa893ad4d557d651718f7787cc111bb44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.9

Release files / pymysql_dao-0.0.11-py3-none-any.whl

Download URL pymysql_dao-0.0.11-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17ef8ec208fd66cae243907efeeb6cdd468bc15274c709906ef9ef06145cdbc6
BLAKE2b-256 checksum
How to use checksums
176d93afa4d76e65935fb214cc8107885d0add0a20d58463b85dbffd0a7c05d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.9

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page