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.5.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

PureMySQL-0.0.5-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: PureMySQL-0.0.5.tar.gz
  • Upload date:
  • Size: 5.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

Hashes for PureMySQL-0.0.5.tar.gz
Algorithm Hash digest
SHA256 776b0578fd882324d49e8b6f3424eea8a8d0c60a85bbe78658111c5737be1aa7
MD5 4260e4c07c2922d45f731079c780eefc
BLAKE2b-256 cdd92e160dc43a96c40dfa9ad30e36ea3ee7c38a6138d7cea203120f65cf8a51

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PureMySQL-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 7.3 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

Hashes for PureMySQL-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0a23ff5bf3ece3a65a1ea8c3fbcbf37e1fceff5e2a43617fc2e8b2343d12b52f
MD5 91afbe7d4d7e13d1e0328336a1e6ac38
BLAKE2b-256 e24ead342fe7d2064318056c32019a57eccf59092f89e9b4f9011124f12399c4

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