Skip to main content

a simple orm in python based on [mysql,dataclass].

Project description

Introduction

License

Code style: black Code style: isort

Imports: mysql-connector-python Imports: dataclasses

a simple orm in python based on [mysql,dataclass].

Install

pip install rinch-sql

Use

dict

  • table

    • __init__.py
    • user.py
    • table2.py
  • task.py

user.py

import datetime
from dataclasses import dataclass


@dataclass
class User:
    field_list_unique = ["name"]  # must, can be []

    name: str
    age: int

    id: int = None  # must
    create_time: datetime = None
    update_time: datetime = None

__init__.py

from rinch_sql import Mysql

# please use every key with current name. dont use it autocommit(always True).
MYSQL_SERVER_DATABASE = {
    "host": "",
    "port": 3306,
    "user": "",
    "password": "",
    "database": "",
    "pool_size": 32,
}

from .user import User

# it will create pool immediately
mysql_user = Mysql(MYSQL_SERVER_DATABASE, User)


# or creat it when use
def mysql_user_():
    return Mysql(MYSQL_SERVER_DATABASE, User)

task.py

from rinch_sql import Sql, SqlStatic
from table import mysql_user, User

# select all
user_list = mysql_user.select("")


# select with where
user_list = mysql_user.select("id = 1")

# select with complex sql
sql = "SELECT id,t1.name,age from user as t1 right join tb_mail as t2 on t1.name=t2.name group by t1.name"
values = ["id", "name", "age"]  # "id,name,age".split(",")
user_record_list = mysql_user.execute(sql)
user_list = [mysql_user._values_2_obj(i, values) for i in user_record_list]

# or you can use Sql or SqlStatic driect
sql_update = SqlStatic.update("user", ["name", "age"])
user = User(id=2)
mysql_user.execute(sql_update, ["name_new", 100])

Advice

when you have any advice, please issue in https://github.com/rinch-wu/rinch_sql

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rinch_sql-10.4.2.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

rinch_sql-10.4.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file rinch_sql-10.4.2.tar.gz.

File metadata

  • Download URL: rinch_sql-10.4.2.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for rinch_sql-10.4.2.tar.gz
Algorithm Hash digest
SHA256 4db03fe490bdb5a9effa9b122463b0fc30c514dc9fd0edf08e67cbcf464b0f54
MD5 95aa92eaaac333f020d84be47f0a94a1
BLAKE2b-256 dd2634b0095e1926f5b5ecaa732cefecb97fbc3da89e31b1c1445391a9e75fda

See more details on using hashes here.

File details

Details for the file rinch_sql-10.4.2-py3-none-any.whl.

File metadata

  • Download URL: rinch_sql-10.4.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for rinch_sql-10.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4db51f2348a1aff3fddcc6684039690ade03d91e0f48f6117c77ef2bc19b71f0
MD5 85ef56b7c6c48c3a50403b42ac5418fe
BLAKE2b-256 60ae26bb3b5939b0660a597e8c7b23606156d9f5506c19f22d04d4bbd625ad7e

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