a simple orm based on [mysql,dataclass].
Project description
Introduction
a simple orm 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
Project details
Release history Release notifications | RSS feed
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-0.1.1.tar.gz
(8.6 kB
view hashes)
Built Distribution
Close
Hashes for rinch_sql-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ee800e158f3863d3ea158a588e4f0ef9e6daf833068b6029488f0b34dabdf72 |
|
MD5 | 7ba857bd912bb49ae3e09925f3b94e88 |
|
BLAKE2b-256 | 07fcf3a5401a0bf62b6c9380dba296709e2fc6f55596b42b3c0392b4121a7642 |