Name | simpysql JSON |
Version |
0.4.10
JSON |
| download |
home_page | |
Summary | A simple mysql orm base on pymysql |
upload_time | 2023-12-27 14:35:56 |
maintainer | |
docs_url | None |
author | jeanku, liubin |
requires_python | >=3 |
license | |
keywords |
mysql
orm
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# SimpySql
一个数据库orm, 目前支持`mysql`, `mongodb`
[mysql文档](./README_mysql.md)
, [mongo文档](./README_mongo.md)
# 安装
```
pip install simpysql
```
# 初始化
你需要在你的项目根目录下创建一个.env文件,内容如下:
``` python
[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:
``` python
#!/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")
```
## 操作实例
```python
ModelDemo.where('id', 4).select('id', 'name').take(5).get()
```
## 其他
欢迎志同道合的朋友一起参与本项目开发SQLServer、PostgreSQL开发, 联系方式: 490573621@qq.com
Raw data
{
"_id": null,
"home_page": "",
"name": "simpysql",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3",
"maintainer_email": "",
"keywords": "MySQL ORM",
"author": "jeanku, liubin",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/07/fc/198ad2152124bba5406bbab86f584a2c4522ced9635f6fc3fdb9d074a1b3/simpysql-0.4.10.tar.gz",
"platform": null,
"description": "# SimpySql\n\n\u4e00\u4e2a\u6570\u636e\u5e93orm, \u76ee\u524d\u652f\u6301`mysql`, `mongodb`\n\n[mysql\u6587\u6863](./README_mysql.md)\n, [mongo\u6587\u6863](./README_mongo.md)\n\n# \u5b89\u88c5\n```\npip install simpysql\n```\n\n# \u521d\u59cb\u5316\n\u4f60\u9700\u8981\u5728\u4f60\u7684\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a.env\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b:\n\n``` python\n[default] #\u6570\u636e\u5e93\u914d\u7f6e\u540d\u79f0(\u5bf9\u5e94model.__database__)\nDB_TYPE=mysql #\u6570\u636e\u5e93\u7c7b\u578b mysql \u6216\u8005 mongo\nDB_HOST=127.0.0.1 #\u6570\u636e\u5e93IP \nDB_PORT=3306 #\u7aef\u53e3\nDB_NAME=test_db1 #\u5e93\u540d\nDB_USER=root #\u8d26\u53f7\nDB_PASSWORD=123456 #\u5bc6\u7801\nDB_CHARSET=utf8mb4 #\u6570\u636e\u5e93\u7f16\u7801\nLOG_DIR=/home/logs/python/ #\u5f00\u542f\u65e5\u5fd7\uff0c \u65e5\u5fd7\u8def\u5f84: /home/logs/python/\n\n[test_db2] #\u5176\u4ed6\u7684\u5e93\nDB_TYPE=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_NAME=test_db2\nDB_USER=root\nDB_PASSWORD=123456\nDB_CHARSET=utf8mb4\n#LOG_DIR=/home/logs/python/ #\u5173\u95ed\u65e5\u5fd7\n```\n\n# \u521b\u5efa\u8868model\n\n\u521b\u5efa\u6570\u636e\u5e93model \u5e76\u7ee7\u627fsimpysql.DBModel:\n\n``` python\n#!/usr/bin/python\n# -*- coding: UTF-8 -*-\nfrom simpysql.DBModel import DBModel\n\nclass ModelDemo(DBModel):\n\n __basepath__ = '/home/project/' # .env \u6587\u4ef6\u8def\u5f84\n #__database__ = 'default' # \u5e93\u9009\u62e9\uff0c \u6ca1\u6709\u8be5\u5c5e\u6027\uff0c\u5219\u9ed8\u8ba4default\u5e93\n __tablename__ = 'lh_test' # table name\n __create_time__ = 'create_time' # \u81ea\u52a8\u6dfb\u52a0\u521b\u5efa\u65f6\u95f4\u5b57\u6bb5create_time(\u7cbe\u786e\u5230\u79d2)\uff0c \u8bbe\u7f6e\u4e3aNone\u6216\u8005\u5220\u9664\u8be5\u5c5e\u6027\uff0c\u5219\u4e0d\u81ea\u52a8\u6dfb\u52a0 \n __update_time__ = 'update_time' # \u81ea\u52a8\u66f4\u65b0\u65f6\u95f4\u5b57\u6bb5update_time(\u7cbe\u786e\u5230\u79d2)\uff0c \u8bbe\u7f6e\u4e3aNone\u6216\u8005\u5220\u9664\u8be5\u5c5e\u6027\uff0c\u5219\u4e0d\u81ea\u52a8\u66f4\u65b0\n columns = [ # table columns\n 'id',\n 'name',\n 'token_name',\n 'status',\n 'create_time',\n 'update_time',\n ]\n\n # \u53ef\u4ee5\u901a\u8fc7\u8be5\u65b9\u6cd5\u8bbe\u7f6e\u81ea\u52a8\u6dfb\u52a0\u65f6\u95f4\u5b57\u6bb5\u7684\u683c\u5f0f\n # def fresh_timestamp(self):\n # return datetime.datetime.now().strftime(\"%Y%m%d\")\n```\n\n## \u64cd\u4f5c\u5b9e\u4f8b\n\n```python\nModelDemo.where('id', 4).select('id', 'name').take(5).get()\n```\n\n## \u5176\u4ed6\n\u6b22\u8fce\u5fd7\u540c\u9053\u5408\u7684\u670b\u53cb\u4e00\u8d77\u53c2\u4e0e\u672c\u9879\u76ee\u5f00\u53d1SQLServer\u3001PostgreSQL\u5f00\u53d1, \u8054\u7cfb\u65b9\u5f0f: 490573621@qq.com\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "A simple mysql orm base on pymysql",
"version": "0.4.10",
"project_urls": null,
"split_keywords": [
"mysql",
"orm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6988326ee9db3d112641b96c4e97d1ffaf4f05f455c319e707fc75d7954f1dad",
"md5": "e75412504f0d28ffb624dfb24c255e6d",
"sha256": "191571fd035103be97ddf617c5ce30233350314326061f2b0df78c0cb0cf46d9"
},
"downloads": -1,
"filename": "simpysql-0.4.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e75412504f0d28ffb624dfb24c255e6d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3",
"size": 34525,
"upload_time": "2023-12-27T14:35:54",
"upload_time_iso_8601": "2023-12-27T14:35:54.060107Z",
"url": "https://files.pythonhosted.org/packages/69/88/326ee9db3d112641b96c4e97d1ffaf4f05f455c319e707fc75d7954f1dad/simpysql-0.4.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "07fc198ad2152124bba5406bbab86f584a2c4522ced9635f6fc3fdb9d074a1b3",
"md5": "196e8e7403e35cda2cc4cc1c9f33ff44",
"sha256": "dcf844f8e4680cdddb1872f8fb6eab8ddfa934fd52a19beeca71659092dba5db"
},
"downloads": -1,
"filename": "simpysql-0.4.10.tar.gz",
"has_sig": false,
"md5_digest": "196e8e7403e35cda2cc4cc1c9f33ff44",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3",
"size": 15350,
"upload_time": "2023-12-27T14:35:56",
"upload_time_iso_8601": "2023-12-27T14:35:56.204517Z",
"url": "https://files.pythonhosted.org/packages/07/fc/198ad2152124bba5406bbab86f584a2c4522ced9635f6fc3fdb9d074a1b3/simpysql-0.4.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-27 14:35:56",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "simpysql"
}