# nonebot_plugin_navicat
[![pypi](https://img.shields.io/pypi/v/nonebot-plugin-navicat.svg)](https://pypi.org/project/nonebot_plugin_navicat/)
![implementation](https://img.shields.io/pypi/implementation/nonebot-plugin-navicat)
![wheel](https://img.shields.io/pypi/wheel/nonebot-plugin-navicat)
![python](https://img.shields.io/pypi/pyversions/nonebot-plugin-navicat)
[![license](https://img.shields.io/github/license/synodriver/nonebot_plugin_navicat.svg)](https://raw.githubusercontent.com/synodriver/nonebot_plugin_navicat/main/LICENSE)
- 基于[nonebot2](https://github.com/nonebot/nonebot2)
## 功能
- 对外暴露出数据库连接 支持mysql mongodb redis
## 开始使用
必须使用 pip
- 通过 pip 从 [PyPI](https://pypi.org/project/nonebot_plugin_navicat/) 安装
``` {.sourceCode .bash}
pip install nonebot-plugin-navicat
```
- 我全都要
``` {.sourceCode .bash}
pip install nonebot-plugin-navicat[all]
```
- 要使用mysql
``` {.sourceCode .bash}
pip install nonebot-plugin-navicat[mysql]
```
- 要使用postgresql
``` {.sourceCode .bash}
pip install nonebot-plugin-navicat[postgresql]
```
- 要使用sqlite
``` {.sourceCode .bash}
pip install nonebot-plugin-navicat[sqlite]
```
- 要使用mongodb
``` {.sourceCode .bash}
pip install nonebot-plugin-navicat[mongodb]
```
- 要使用redis
``` {.sourceCode .bash}
pip install nonebot-plugin-navicat[redis]
```
- 要使用elasticsearch
``` {.sourceCode .bash}
pip install nonebot-plugin-navicat[elasticsearch]
```
- 在 nonebot2 项目中设置 load_plugin()
``` {.sourceCode .python}
nonebot.load_plugin('nonebot_plugin_navicat')
```
- 参照下文在 nonebot2 项目的环境文件 .env.\* 中添加配置项
## 配置项
配置数据库连接
```
# mysql 如果有MYSQL_HOST则表示要进行mysql连接
MYSQL_HOST=
MYSQL_PORT=
MYSQL_USER=
MYSQL_PASSWORD=
MYSQL_DB=
# postgresql 如果有PGSQL_HOST则表示要进行postgresql连接
PGSQL_HOST=
PGSQL_PORT=
PGSQL_USER=
PGSQL_PASSWORD=
PGSQL_DB=
# sqlite 如果有SQLITE_HOST则表示要进行sqlite连接 这里是路径
SQLITE_HOST=
# mongodb 如果有MONGODB_HOST则表示要进行mongodb连接
MONGODB_HOST=
MONGODB_PORT=
MONGODB_USER=
MONGODB_PASSWORD=
# redis 如果有REDIS_HOST则表示要进行redis连接
REDIS_PARAMS={"decode_responses":true}
REDIS_HOST=
REDIS_PORT=
REDIS_PASSWORD=
REDIS_DB=
# redis sentinel 如果有REDIS_SENTINEL_PARAMS则表示要进行redis sentinel连接
REDIS_SENTINEL_PARAMS=
REDIS_SENTINEL_SERVICE_NAME= # 必填
# redis cluster 如果有REDIS_CLUSTER_PARAMS则表示要进行redis cluster连接
REDIS_CLUSTER_PARAMS=
REDIS_CLUSTER_NODES=
# 集群没有db选项
# elasticsearch 如果有ELASTICSEARCH_PARAMS则表示要进行elasticsearch连接
ELASTICSEARCH_PARAMS=
ELASTICSEARCH_HOSTS=
# 以后会加入更多数据库支持
```
## 导出给其他插件
```{.sourceCode .python}
from nonebot import require
require("nonebot_plugin_navicat")
import nonebot_plugin_navicat as export # 兼容老写法,不至于大改
export.mysql_pool # mysql的
export.pgsql_pool # postgresql的
export.sqlite_pool # sqlite的
export.mongodb_client # mongodb的
export.redis_client # redis的
export.redis_sentinel
export.redis_cluster
export.elasticsearch # elasticsearch的
```
## 直接查询数据库 (0.2.0中已删除)
- 危险功能! 在配置中启用```NAVICAT_EXECUTE_SQL=true```来开启
- 使用方法:发送```super ${dbname} + sql```来查询
```
super mysql
show databases
```
## 更新记录
- v0.3.0rc1 适配nonebot rc版本
- v0.2.3 修复beta2的bug
- v0.2.1 加入了对redis哨兵和集群的支持,对```elasticsearch```的支持
- v0.2.0 使用 [databases](https://github.com/encode/databases/) 代替直接连接,有了广泛的通用性
- 移除了直接命令行查询数据库的功能,迁移到了单独的一个插件里面 *[nonebot-plugin-super](https://github.com/synodriver/nonebot_plugin_super)*
## 特别感谢
- [Mrs4s / go-cqhttp](https://github.com/Mrs4s/go-cqhttp)
- [nonebot / nonebot2](https://github.com/nonebot/nonebot2)
## 优化建议
- bug report
- more databases support
![](https://i.pixiv.cat/img-original/img/2018/08/29/00/16/10/70434240_p0.png "bug哪里跑 看姐姐给你们全抓起来~")
Raw data
{
"_id": null,
"home_page": "https://github.com/synodriver/nonebot_plugin_navicat",
"name": "nonebot-plugin-navicat",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "nonebot",
"author": "synodriver",
"author_email": "diguohuangjiajinweijun@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/38/37/57d56b4bab15c4ad504f78a9c92c6e542b547c8ec0364311c87da08c69f3/nonebot-plugin-navicat-0.4.0.tar.gz",
"platform": null,
"description": "# nonebot_plugin_navicat\r\n[![pypi](https://img.shields.io/pypi/v/nonebot-plugin-navicat.svg)](https://pypi.org/project/nonebot_plugin_navicat/) \r\n![implementation](https://img.shields.io/pypi/implementation/nonebot-plugin-navicat)\r\n![wheel](https://img.shields.io/pypi/wheel/nonebot-plugin-navicat)\r\n![python](https://img.shields.io/pypi/pyversions/nonebot-plugin-navicat)\r\n[![license](https://img.shields.io/github/license/synodriver/nonebot_plugin_navicat.svg)](https://raw.githubusercontent.com/synodriver/nonebot_plugin_navicat/main/LICENSE)\r\n\r\n- \u57fa\u4e8e[nonebot2](https://github.com/nonebot/nonebot2)\r\n\r\n## \u529f\u80fd\r\n\r\n- \u5bf9\u5916\u66b4\u9732\u51fa\u6570\u636e\u5e93\u8fde\u63a5 \u652f\u6301mysql mongodb redis\r\n\r\n## \u5f00\u59cb\u4f7f\u7528\r\n\r\n\u5fc5\u987b\u4f7f\u7528 pip\r\n\r\n- \u901a\u8fc7 pip \u4ece [PyPI](https://pypi.org/project/nonebot_plugin_navicat/) \u5b89\u88c5\r\n\r\n``` {.sourceCode .bash}\r\npip install nonebot-plugin-navicat\r\n```\r\n- \u6211\u5168\u90fd\u8981\r\n``` {.sourceCode .bash}\r\npip install nonebot-plugin-navicat[all]\r\n```\r\n- \u8981\u4f7f\u7528mysql\r\n``` {.sourceCode .bash}\r\npip install nonebot-plugin-navicat[mysql]\r\n```\r\n- \u8981\u4f7f\u7528postgresql\r\n``` {.sourceCode .bash}\r\npip install nonebot-plugin-navicat[postgresql]\r\n```\r\n- \u8981\u4f7f\u7528sqlite\r\n``` {.sourceCode .bash}\r\npip install nonebot-plugin-navicat[sqlite]\r\n```\r\n- \u8981\u4f7f\u7528mongodb\r\n``` {.sourceCode .bash}\r\npip install nonebot-plugin-navicat[mongodb]\r\n```\r\n- \u8981\u4f7f\u7528redis\r\n``` {.sourceCode .bash}\r\npip install nonebot-plugin-navicat[redis]\r\n```\r\n- \u8981\u4f7f\u7528elasticsearch\r\n``` {.sourceCode .bash}\r\npip install nonebot-plugin-navicat[elasticsearch]\r\n```\r\n\r\n- \u5728 nonebot2 \u9879\u76ee\u4e2d\u8bbe\u7f6e load_plugin()\r\n\r\n``` {.sourceCode .python}\r\nnonebot.load_plugin('nonebot_plugin_navicat')\r\n```\r\n\r\n- \u53c2\u7167\u4e0b\u6587\u5728 nonebot2 \u9879\u76ee\u7684\u73af\u5883\u6587\u4ef6 .env.\\* \u4e2d\u6dfb\u52a0\u914d\u7f6e\u9879\r\n\r\n## \u914d\u7f6e\u9879\r\n\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\r\n```\r\n# mysql \u5982\u679c\u6709MYSQL_HOST\u5219\u8868\u793a\u8981\u8fdb\u884cmysql\u8fde\u63a5\r\nMYSQL_HOST=\r\nMYSQL_PORT=\r\nMYSQL_USER=\r\nMYSQL_PASSWORD=\r\nMYSQL_DB=\r\n\r\n# postgresql \u5982\u679c\u6709PGSQL_HOST\u5219\u8868\u793a\u8981\u8fdb\u884cpostgresql\u8fde\u63a5\r\nPGSQL_HOST=\r\nPGSQL_PORT=\r\nPGSQL_USER=\r\nPGSQL_PASSWORD=\r\nPGSQL_DB=\r\n\r\n# sqlite \u5982\u679c\u6709SQLITE_HOST\u5219\u8868\u793a\u8981\u8fdb\u884csqlite\u8fde\u63a5 \u8fd9\u91cc\u662f\u8def\u5f84\r\nSQLITE_HOST=\r\n\r\n# mongodb \u5982\u679c\u6709MONGODB_HOST\u5219\u8868\u793a\u8981\u8fdb\u884cmongodb\u8fde\u63a5\r\nMONGODB_HOST=\r\nMONGODB_PORT=\r\nMONGODB_USER=\r\nMONGODB_PASSWORD=\r\n\r\n# redis \u5982\u679c\u6709REDIS_HOST\u5219\u8868\u793a\u8981\u8fdb\u884credis\u8fde\u63a5\r\nREDIS_PARAMS={\"decode_responses\":true}\r\nREDIS_HOST=\r\nREDIS_PORT=\r\nREDIS_PASSWORD=\r\nREDIS_DB=\r\n\r\n# redis sentinel \u5982\u679c\u6709REDIS_SENTINEL_PARAMS\u5219\u8868\u793a\u8981\u8fdb\u884credis sentinel\u8fde\u63a5\r\nREDIS_SENTINEL_PARAMS=\r\nREDIS_SENTINEL_SERVICE_NAME= # \u5fc5\u586b\r\n\r\n# redis cluster \u5982\u679c\u6709REDIS_CLUSTER_PARAMS\u5219\u8868\u793a\u8981\u8fdb\u884credis cluster\u8fde\u63a5\r\nREDIS_CLUSTER_PARAMS=\r\nREDIS_CLUSTER_NODES=\r\n# \u96c6\u7fa4\u6ca1\u6709db\u9009\u9879\r\n\r\n# elasticsearch \u5982\u679c\u6709ELASTICSEARCH_PARAMS\u5219\u8868\u793a\u8981\u8fdb\u884celasticsearch\u8fde\u63a5\r\nELASTICSEARCH_PARAMS=\r\nELASTICSEARCH_HOSTS=\r\n\r\n\r\n# \u4ee5\u540e\u4f1a\u52a0\u5165\u66f4\u591a\u6570\u636e\u5e93\u652f\u6301\r\n```\r\n## \u5bfc\u51fa\u7ed9\u5176\u4ed6\u63d2\u4ef6\r\n\r\n```{.sourceCode .python}\r\nfrom nonebot import require\r\n\r\nrequire(\"nonebot_plugin_navicat\")\r\nimport nonebot_plugin_navicat as export # \u517c\u5bb9\u8001\u5199\u6cd5\uff0c\u4e0d\u81f3\u4e8e\u5927\u6539\r\n\r\nexport.mysql_pool # mysql\u7684\r\n\r\nexport.pgsql_pool # postgresql\u7684\r\n\r\nexport.sqlite_pool # sqlite\u7684\r\n\r\nexport.mongodb_client # mongodb\u7684\r\n\r\nexport.redis_client # redis\u7684\r\nexport.redis_sentinel\r\nexport.redis_cluster\r\n\r\nexport.elasticsearch # elasticsearch\u7684\r\n```\r\n\r\n## \u76f4\u63a5\u67e5\u8be2\u6570\u636e\u5e93 (0.2.0\u4e2d\u5df2\u5220\u9664)\r\n- \u5371\u9669\u529f\u80fd! \u5728\u914d\u7f6e\u4e2d\u542f\u7528```NAVICAT_EXECUTE_SQL=true```\u6765\u5f00\u542f\r\n- \u4f7f\u7528\u65b9\u6cd5:\u53d1\u9001```super ${dbname} + sql```\u6765\u67e5\u8be2\r\n```\r\nsuper mysql\r\nshow databases\r\n```\r\n## \u66f4\u65b0\u8bb0\u5f55\r\n- v0.3.0rc1 \u9002\u914dnonebot rc\u7248\u672c\r\n\r\n- v0.2.3 \u4fee\u590dbeta2\u7684bug\r\n\r\n\r\n- v0.2.1 \u52a0\u5165\u4e86\u5bf9redis\u54e8\u5175\u548c\u96c6\u7fa4\u7684\u652f\u6301\uff0c\u5bf9```elasticsearch```\u7684\u652f\u6301\r\n\r\n\r\n\r\n- v0.2.0 \u4f7f\u7528 [databases](https://github.com/encode/databases/) \u4ee3\u66ff\u76f4\u63a5\u8fde\u63a5,\u6709\u4e86\u5e7f\u6cdb\u7684\u901a\u7528\u6027\r\n- \u79fb\u9664\u4e86\u76f4\u63a5\u547d\u4ee4\u884c\u67e5\u8be2\u6570\u636e\u5e93\u7684\u529f\u80fd,\u8fc1\u79fb\u5230\u4e86\u5355\u72ec\u7684\u4e00\u4e2a\u63d2\u4ef6\u91cc\u9762 *[nonebot-plugin-super](https://github.com/synodriver/nonebot_plugin_super)*\r\n## \u7279\u522b\u611f\u8c22\r\n\r\n- [Mrs4s / go-cqhttp](https://github.com/Mrs4s/go-cqhttp)\r\n- [nonebot / nonebot2](https://github.com/nonebot/nonebot2)\r\n\r\n## \u4f18\u5316\u5efa\u8bae\r\n\r\n- bug report\r\n- more databases support\r\n![](https://i.pixiv.cat/img-original/img/2018/08/29/00/16/10/70434240_p0.png \"bug\u54ea\u91cc\u8dd1 \u770b\u59d0\u59d0\u7ed9\u4f60\u4eec\u5168\u6293\u8d77\u6765~\")\r\n",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "A batabase manager plugin for nonebot2,provide capability of connection to all kinds of databases",
"version": "0.4.0",
"project_urls": {
"Bug Tracker": "https://github.com/synodriver/nonebot_plugin_navicat/issues",
"Homepage": "https://github.com/synodriver/nonebot_plugin_navicat"
},
"split_keywords": [
"nonebot"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "10a12df3e8de76bae483a009d9d7a9705d9a2b5ec0e5973ae08ef4d7d6548c88",
"md5": "8d327425c3aa45e9aa6ad539226260ca",
"sha256": "c93a99e78686a14476c10ef523562e7ae457517027881209062d860217195ded"
},
"downloads": -1,
"filename": "nonebot_plugin_navicat-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8d327425c3aa45e9aa6ad539226260ca",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 21256,
"upload_time": "2024-09-21T08:09:19",
"upload_time_iso_8601": "2024-09-21T08:09:19.970421Z",
"url": "https://files.pythonhosted.org/packages/10/a1/2df3e8de76bae483a009d9d7a9705d9a2b5ec0e5973ae08ef4d7d6548c88/nonebot_plugin_navicat-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "383757d56b4bab15c4ad504f78a9c92c6e542b547c8ec0364311c87da08c69f3",
"md5": "bbb0ac8706e9521877f0e91b93979027",
"sha256": "63e7e18666cac950f262d1599a89581eac24d41d84c62495cf5972f7423db845"
},
"downloads": -1,
"filename": "nonebot-plugin-navicat-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "bbb0ac8706e9521877f0e91b93979027",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 21089,
"upload_time": "2024-09-21T08:09:21",
"upload_time_iso_8601": "2024-09-21T08:09:21.801446Z",
"url": "https://files.pythonhosted.org/packages/38/37/57d56b4bab15c4ad504f78a9c92c6e542b547c8ec0364311c87da08c69f3/nonebot-plugin-navicat-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-21 08:09:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "synodriver",
"github_project": "nonebot_plugin_navicat",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "nonebot-plugin-navicat"
}