Skip to main content

A functional enhancement package that focus on crud based PyMySQL

Project description

PyMySQLDao

Introduce

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

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

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

Requirements

PyMySQL

termcolor

colorama(only in windows)

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/

Example

假设使用下列SQL语句:

create database python_example;

use python_example;

create table class (
   id bigint(20) primary key auto_increment,
   class_name varchar(50) not null unique,
   is_delete tinyint default 0,
   index idx_clsname(class_name)
)engine=innodb
 auto_increment=1
 default charset=utf8;
 
insert into class(id, class_name) values(1, "火箭班");
insert into class(class_name) values("骏马班");

使用pymysqldao轻松的进行CRUD

import pymysql
from pymysqldao import BaseDao

db_example_conn = pymysql.connect(
    host='localhost',
    user='root',
    password='root',
    database='python_example',
    cursorclass=pymysql.cursors.DictCursor
)


class ClassDao(BaseDao):
    def __init__(self):
        super(ClassDao, self).__init__(db_example_conn, "class")


if __name__ == '__main__':
    class_dao = ClassDao()

    # select by id
    class_dao.select_by_id(1)
    class_dao.select_by_id("1")
    class_dao.select_by_id(1, primary_key="id")

    # select by field
    class_dao.select_by_field("xxx", field_key="class_name")
    class_dao.select_by_field("xxx", field_key="class_name", limit_size=10)

    # select list
    class_dao.select_list()
    class_dao.select_list(limit_size=500)

    # select by id_list
    class_dao.select_by_id_list([1, 2, 3])  # default primary_key is "id"
    class_dao.select_by_id_list([1, 2, 3], primary_key="class_id")
    
    # insert
    obj_dict = {"class_name": "少年班"}
    class_dao.insert_one(obj_dict)
    
    # update
    new_obj_id_1 = {'id': 1, 'class_name': '火箭班修改', 'is_delete': 0}
    class_dao.update_by_id(new_obj_id_1)
    
    # delete
    class_dao.delete_by_id(1)
    class_dao.delete_by_id(1, primary_key="class_id")

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

pymysql_dao-0.0.5.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

pymysql_dao-0.0.5-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file pymysql_dao-0.0.5.tar.gz.

File metadata

  • Download URL: pymysql_dao-0.0.5.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9

File hashes

Hashes for pymysql_dao-0.0.5.tar.gz
Algorithm Hash digest
SHA256 2a5e0acd37cec2bdb648a1530543ccfba42c1da6e1bdfd1872a87ca598f4b406
MD5 2712df074df872b07285217d10517263
BLAKE2b-256 1cfce911fb5200a26b461ff30d7864f48f5962db26f14e077c4482e24a6276f5

See more details on using hashes here.

File details

Details for the file pymysql_dao-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pymysql_dao-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9

File hashes

Hashes for pymysql_dao-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ceeeda960684daeeb67d83c17f55108904b11b5725c435b7ce83fcb0ea264295
MD5 4e9af13c1a9cc63cf0f2b0c0b71e72bd
BLAKE2b-256 1d0fb854288dbab2ccff7ee62a4251a508d7bb5e07d1584ce39e10374cc81f9e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page