pythink
灵感来自于ThinkPHP 部分代码实现参考了 records
根据现有业务 实现了简单的增删改查, 可以用作日常助手
依赖:
SQLAlchemy>=1.2.8 ps:原来基于peewee实现的,不过问题较多,就直接用SQLAlchemy
安装
pip install pythink
快速开始
新建表
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) DEFAULT NULL,
`name` varchar(20) DEFAULT '',
`age` int(11),
`create_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
代码示例
1、连接数据库,创建Model
# -*- coding: utf-8 -*-
from pythink import ThinkModel, ThinkDatabase
db_url = "mysql://root:123456@127.0.01:3306/demo"
db = ThinkDatabase(db_url)
class StudentThinkModel(ThinkModel):
table_name = "student"
database = db
2、插入操作
# 1、增加单条记录
data = {
"name": "Tom"
}
>>> StudentThinkModel.insert(data)
>>> 1
# 2、增加多条记录
data = [
{
"name": "Tom",
},
{
"name": "Jack"
}
]
>>> StudentThinkModel.insert(data)
>>> 2
# 3、插入多条 分段插入
data = [
{
"name": "Tom",
"age": 24,
},
{
"name": "Tom",
"age": 25,
},
{
"name": "Tom",
"age": 26,
},
{
"name": "Tom",
"age": 27,
},
{
"name": "Tom",
"age": 28,
},
{
"name": "Tom",
"age": 29,
}
]
# 每次插入3 条数据
>>> StudentThinkModel.insert(data, truncate=3)
>>> 6
3、查询操作
# 1、查询数量
>>> StudentThinkModel.count()
>>> 24
# 2、查询记录
rows = StudentThinkModel.select(["name", "age"], where="id>25", limit=5)
for row in rows:
print(row.name, row.age)
# ('Tom', 25L)
# ('Tom', 26L)
# ('Tom', 27L)
# ('Tom', 28L)
# ('Tom', 29L)
4、更新操作
# 条件更新
data = {
"name": "tom",
"age": 30
}
>>> StudentThinkModel.update(data, "id=25")
>>> 1
5、删除操作
# 删除
>>> StudentThinkModel.delete("id=13")
>>> 1
Metadata
Release files for pythink 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pythink-0.0.5.tar.gz | 9.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pythink-0.0.5-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 20.7 kB
Release files / pythink-0.0.5.tar.gz
| Download URL | pythink-0.0.5.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7649dd9898c99c4f915eafaaeae0531338d68e82daa4114a442d0c9f43e7ef02
|
|
BLAKE2b-256 checksum How to use checksums |
cd0685de5b5cf2e1e9ce13dc968ad4715e0ff15e7b8c0348bb7b1ffcb38bd606
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.10.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.7 CPython/3.6.5
|
Release files / pythink-0.0.5-py2-none-any.whl
| Download URL | pythink-0.0.5-py2-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
dfa2c94f7c8c69f99ef499954bad34f6c5b684f5960fa2c6e1d43b355f732bf2
|
|
BLAKE2b-256 checksum How to use checksums |
6e50cafbc2619e94c3f519ac3ca06d30a5a2d8689b0a5f0e14369fd6552fbf83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.10.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.7 CPython/3.6.5
|
Security for pythink 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.