|
1 | 1 | # gino-quart |
2 | 2 |
|
3 | | -An extension for GINO to support Quart server. |
| 3 | + |
4 | 4 |
|
5 | | -**This project "gino-quart" is currently not maintained and needs adoption.** |
| 5 | +## Introduction |
6 | 6 |
|
7 | | -Since GINO 1.0, the built-in extensions are now separate projects supported by |
8 | | -the community. This project is copied here directly from GINO 0.8.x for |
9 | | -compatibility. Help is needed to: |
| 7 | +An extension for GINO to support [quart](https://gitlab.com/pgjones/quart) server. |
10 | 8 |
|
11 | | -* Keep this project maintained - follow Quart releases, fix issues, etc. |
12 | | -* Add more examples and documentation. |
13 | | -* Answer questions in the community. |
| 9 | +## Usage |
| 10 | + |
| 11 | +The common usage looks like this: |
| 12 | + |
| 13 | +```python |
| 14 | +from quart import Quart |
| 15 | +from gino.ext.quart import Gino |
| 16 | + |
| 17 | +app = Quart() |
| 18 | +db = Gino(app, **kwargs) |
| 19 | +``` |
| 20 | + |
| 21 | +## Configuration |
| 22 | + |
| 23 | +GINO adds a `before_request`, `after_request` and `before_first_request` hook to the Quart app to setup and cleanup database according to |
| 24 | +the configurations that passed in the `kwargs` parameter. |
| 25 | + |
| 26 | +The config includes: |
| 27 | + |
| 28 | +| Name | Description | Default | |
| 29 | +| ---------------------------- | ----------------------------------------------------------------------------------------------------------------- | ----------- | |
| 30 | +| `driver` | the database driver | `asyncpg` | |
| 31 | +| `host` | database server host | `localhost` | |
| 32 | +| `port` | database server port | `5432` | |
| 33 | +| `user` | database server user | `postgres` | |
| 34 | +| `password` | database server password | empty | |
| 35 | +| `database` | database name | `postgres` | |
| 36 | +| `dsn` | a SQLAlchemy database URL to create the engine, its existence will replace all previous connect arguments. | N/A | |
| 37 | +| `retry_times` | the retry times when database failed to connect | `20` | |
| 38 | +| `retry_interval` | the interval in **seconds** between each time of retry | `5` | |
| 39 | +| `pool_min_size` | the initial number of connections of the db pool. | N/A | |
| 40 | +| `pool_max_size` | the maximum number of connections in the db pool. | N/A | |
| 41 | +| `echo` | enable SQLAlchemy echo mode. | N/A | |
| 42 | +| `ssl` | SSL context passed to `asyncpg.connect` | `None` | |
| 43 | +| `use_connection_for_request` | flag to set up lazy connection for requests. | N/A | |
| 44 | +| `retry_limit` | the number of retries to connect to the database on start up. | 1 | |
| 45 | +| `retry_interval` | seconds to wait between retries. | 1 | |
| 46 | +| `kwargs` | other parameters passed to the specified dialects, like `asyncpg`. Unrecognized parameters will cause exceptions. | N/A | |
| 47 | + |
| 48 | +## Lazy Connection |
| 49 | + |
| 50 | +If `use_connection_for_request` is set to be True, then a lazy connection is available |
| 51 | +at `request['connection']`. By default, a database connection is borrowed on the first |
| 52 | +query, shared in the same execution context, and returned to the pool on response. |
| 53 | +If you need to release the connection early in the middle to do some long-running tasks, |
| 54 | +you can simply do this: |
| 55 | + |
| 56 | +```python |
| 57 | +await request['connection'].release(permanent=False) |
| 58 | +``` |
0 commit comments