Name | simpysqls JSON |
Version |
0.5.12
JSON |
| download |
home_page | None |
Summary | A simple mysql orm base on pymysql |
upload_time | 2024-08-12 08:04:00 |
maintainer | None |
docs_url | None |
author | jeanku, liubin |
requires_python | >=3 |
license | None |
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)
, [cassandra文档](./README_cassandra.md)
# 安装
```
pip install simpysqls
```
# 初始化
你需要在你的项目根目录下创建一个.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": null,
"name": "simpysqls",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3",
"maintainer_email": null,
"keywords": "MySQL ORM",
"author": "jeanku, liubin",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/d3/4c/5d03bb85ec6e03542a880cf5a6a0f95166798aef41b7c5d9096abcb5849e/simpysqls-0.5.12.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, [cassandra\u6587\u6863](./README_cassandra.md)\n\n# \u5b89\u88c5\n```\npip install simpysqls\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",
"bugtrack_url": null,
"license": null,
"summary": "A simple mysql orm base on pymysql",
"version": "0.5.12",
"project_urls": null,
"split_keywords": [
"mysql",
"orm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5a8b323ac53e66a3526f663e5b0966ba99bcdb7f0d5a1036bd6a394c642284f6",
"md5": "2c1aa2a788e3a1d408459da821b79da0",
"sha256": "089fcf53220fb0ec4f91500aeca49ff30651c0d43ce258118dc5d4aef63a781f"
},
"downloads": -1,
"filename": "simpysqls-0.5.12-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2c1aa2a788e3a1d408459da821b79da0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3",
"size": 40471,
"upload_time": "2024-08-12T08:03:59",
"upload_time_iso_8601": "2024-08-12T08:03:59.156662Z",
"url": "https://files.pythonhosted.org/packages/5a/8b/323ac53e66a3526f663e5b0966ba99bcdb7f0d5a1036bd6a394c642284f6/simpysqls-0.5.12-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d34c5d03bb85ec6e03542a880cf5a6a0f95166798aef41b7c5d9096abcb5849e",
"md5": "d0f613a2a779067ad50e496d0d043972",
"sha256": "57cf7c42de1506bbad9de3c4c7e36d39f4267017f9332c47d2c8b863a2e19a7c"
},
"downloads": -1,
"filename": "simpysqls-0.5.12.tar.gz",
"has_sig": false,
"md5_digest": "d0f613a2a779067ad50e496d0d043972",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3",
"size": 20744,
"upload_time": "2024-08-12T08:04:00",
"upload_time_iso_8601": "2024-08-12T08:04:00.716516Z",
"url": "https://files.pythonhosted.org/packages/d3/4c/5d03bb85ec6e03542a880cf5a6a0f95166798aef41b7c5d9096abcb5849e/simpysqls-0.5.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-12 08:04:00",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "simpysqls"
}