SimpySql
一个数据库orm, 目前支持mysql, mongodb
安装
pip install simpysql
初始化
你需要在你的项目根目录下创建一个.env文件,内容如下:
[default] #数据库配置名称(对应model.__database__)
DB_TYPE=mysql #数据库类型 mysql 或者 mongo
DB_HOST=127.0.0.1 #数据库IP
DB_PORT=3306 #端口
DB_NAME=test_db1 #库名
DB_USER=root #账号
DB_PASSWORD=123456 #密码
DB_CHARSET=utf8mb4 #数据库编码
LOG_DIR=/home/logs/python/ #开启日志, 日志路径: /home/logs/python/
[test_db2] #其他的库
DB_TYPE=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=test_db2
DB_USER=root
DB_PASSWORD=123456
DB_CHARSET=utf8mb4
#LOG_DIR=/home/logs/python/ #关闭日志
创建表model
创建数据库model 并继承simpysql.DBModel:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from simpysql.DBModel import DBModel
class ModelDemo(DBModel):
__basepath__ = '/home/project/' # .env 文件路径
#__database__ = 'default' # 库选择, 没有该属性,则默认default库
__tablename__ = 'lh_test' # table name
__create_time__ = 'create_time' # 自动添加创建时间字段create_time(精确到秒), 设置为None或者删除该属性,则不自动添加
__update_time__ = 'update_time' # 自动更新时间字段update_time(精确到秒), 设置为None或者删除该属性,则不自动更新
columns = [ # table columns
'id',
'name',
'token_name',
'status',
'create_time',
'update_time',
]
# 可以通过该方法设置自动添加时间字段的格式
# def fresh_timestamp(self):
# return datetime.datetime.now().strftime("%Y%m%d")
操作实例
ModelDemo.where('id', 4).select('id', 'name').take(5).get()
其他
欢迎志同道合的朋友一起参与本项目开发SQLServer、PostgreSQL开发, 联系方式: 490573621@qq.com
Metadata
Release files for simpysql 0.4.10
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 | Actions |
|---|---|---|---|---|
| simpysql-0.4.10.tar.gz | 15.3 kB | Without provenance | Details for simpysql-0.4.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simpysql-0.4.10-py3-none-any.whl | Python 3 | none | any | Details for simpysql-0.4.10-py3-none-any.whl |
Total release size: 49.9 kB
Release files / simpysql-0.4.10.tar.gz
| Download URL | simpysql-0.4.10.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dcf844f8e4680cdddb1872f8fb6eab8ddfa934fd52a19beeca71659092dba5db
|
|
BLAKE2b-256 checksum How to use checksums |
07fc198ad2152124bba5406bbab86f584a2c4522ced9635f6fc3fdb9d074a1b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.27.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Release files / simpysql-0.4.10-py3-none-any.whl
| Download URL | simpysql-0.4.10-py3-none-any.whl |
|---|---|
| Size | 34.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
191571fd035103be97ddf617c5ce30233350314326061f2b0df78c0cb0cf46d9
|
|
BLAKE2b-256 checksum How to use checksums |
6988326ee9db3d112641b96c4e97d1ffaf4f05f455c319e707fc75d7954f1dad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.27.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Security for simpysql 0.4.10
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.