gino.ext.aiohttp module¶
-
class
gino.ext.aiohttp.
AiohttpStrategy
[source]¶ Bases:
gino.strategies.GinoStrategy
-
engine_cls
¶ alias of
GinoEngine
-
name
= 'aiohttp'¶
-
-
class
gino.ext.aiohttp.
Gino
(bind=None, model_classes=None, query_ext=True, schema_ext=True, ext=True, **kwargs)[source]¶ Bases:
gino.api.Gino
Support aiohttp.web server.
The common usage looks like this:
from aiohttp import web from gino.ext.aiohttp import Gino db = Gino() app = web.Application(middlewares=[db]) db.init_app(app)
By
init_app()
GINO subscribes to a few signals on aiohttp, so that GINO could use database configuration to initialize the bound engine.The configuration can be passed in the
config
parameter ofinit_app
, or if that is not set, in app[‘config’][‘gino’], both of which should be a dictionary.The config includes:
driver
- the database driver, default isasyncpg
.host
- database server host, default islocalhost
.port
- database server port, default is5432
.user
- database server user, default ispostgres
.password
- database server password, default is empty.database
- database name, default ispostgres
.dsn
- a SQLAlchemy database URL to create the engine, its existence will replace all previous connect arguments.pool_min_size
- the initial number of connections of the db pool.pool_max_size
- the maximum number of connections in the db pool.echo
- enable SQLAlchemy echo mode.ssl
- SSL context passed toasyncpg.connect
, default isNone
.kwargs
- other parameters passed to the specified dialects, likeasyncpg
. Unrecognized parameters will cause exceptions.
If the
db
is set as an aiohttp middleware, then a lazy connection is available atrequest['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)
- Parameters
bind – A
GinoEngine
instance to bind. Also accepts string orURL
, which will be passed tocreate_engine()
when thisGino
instance is awaited. Default isNone
.model_classes – A
tuple
of base class and mixin classes to create theModel
class. Default is(CRUDModel, )
.query_ext – Boolean value to control the installation of the
gino
extension onExecutable
for implicit execution. Default is to install (True
).schema_ext – Boolean value to control the installation of the
gino
extension onSchemaItem
for implicit execution. Default is to install (True
).ext – Boolean value to control the installation of the two
gino
extensions.False
for no extension at all, while it depends on the two individual switches when this is set toTrue
(default).kwargs – Other arguments accepted by
MetaData
.
-
model_base_classes
= (<class 'gino.crud.CRUDModel'>, <class 'gino.ext.aiohttp.AiohttpModelMixin'>)¶
-
query_executor
¶ alias of
GinoExecutor
-
class
gino.ext.aiohttp.
GinoConnection
(dialect, sa_conn, stack=None)[source]¶ Bases:
gino.engine.GinoConnection
-
class
gino.ext.aiohttp.
GinoEngine
(dialect, pool, loop, logging_name=None, echo=None, execution_options=None)[source]¶ Bases:
gino.engine.GinoEngine
-
connection_cls
¶ alias of
GinoConnection
-
-
class
gino.ext.aiohttp.
GinoExecutor
(query)[source]¶ Bases:
gino.api.GinoExecutor