- 欢迎来到 GINO 的文档
- 上手教程
- 进阶用法
- 原理说明
- 参考手册
- API 参考
- gino.bakery module
- gino.api module
- gino.declarative module
- gino.schema module
- gino.crud module
- gino.json_support module
- gino.engine module
- gino.loader module
- gino.dialects.asyncpg module
- gino.dialects.base module
- gino.transaction module
- gino.dialects package
- gino.dialects.aiomysql module
- gino.ext package
- gino.aiocontextvars module
- gino.exceptions module
- gino.strategies module
- 扩展
- 版本历史
- API 参考
Starlette Support
Work with Starlette
To use GINO with Starlette, the gino-starlette package should be installed first:
pip install gino-starlette
注解
The gino-starlette package supports only GINO 1.0 or later. Earlier versions of GINO like 0.8.x have built-in Starlette support.
This extension provides a Starlette middleware to setup and cleanup database according to the configurations that passed in the kwargs
parameter.
The common usage looks like this:
from starlette.applications import Starlette from gino.ext.starlette import Gino app = Starlette() db = Gino(app, **kwargs) # Or with application factory app = Starlette() db = Gino(**kwargs) db.init_app(app)
Configuration
The config includes:
Name | Description | Default |
---|---|---|
| the database driver |
|
| database server host |
|
| database server port |
|
| database server user |
|
| database server password | empty |
| database name |
|
| a SQLAlchemy database URL to create the engine, its existence will replace all previous connect arguments. | N/A |
| the initial number of connections of the db pool. | N/A |
| the maximum number of connections in the db pool. | N/A |
| enable SQLAlchemy echo mode. | N/A |
| SSL context passed to |
|
| flag to set up lazy connection for requests. | N/A |
| other parameters passed to the specified dialects, like | N/A |
Lazy Connection
If use_connection_for_request
is set to be True, then a lazy connection is available at request['connection']
. By default, a database connection is borrowed on the first query, shared in the same execution context, and returned to the pool on response. If you need to release the connection early in the middle to do some long-running tasks, you can simply do this:
await request['connection'].release(permanent=False)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论