Skip to main content

一个MySQL简单操作方式

Project description

PureMySQL

PyPI

一个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.10.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

PureMySQL-0.0.10-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file PureMySQL-0.0.10.tar.gz.

File metadata

  • Download URL: PureMySQL-0.0.10.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for PureMySQL-0.0.10.tar.gz
Algorithm Hash digest
SHA256 63d4036649ee9cd034b800eefe068bae01a3fa746f165ec996fe16d6b6aea524
MD5 4047f67f5cfb46e6df7d3a334c15e80a
BLAKE2b-256 c7d531a818b588ec69651ec2fa3959b2bf94c1c2d600f6c26c2dc72d6e75acda

See more details on using hashes here.

File details

Details for the file PureMySQL-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: PureMySQL-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for PureMySQL-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 d73d4b3474a9c4fbafd9b1421c2ff76a071b295c7110d806aeece80db7bfc986
MD5 4826e246305a40fd3fa62df351fc1b85
BLAKE2b-256 e61c3c8ae45a79298a1a76e2973eea5787e16d7e45cc17f117b35232dfc163f6

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