22
33# noinspection PyPackageRequirements
44from quart import Quart , request
5+
56# noinspection PyPackageRequirements
67from quart .exceptions import NotFound
78from sqlalchemy .engine .url import URL
@@ -48,7 +49,7 @@ async def first_or_404(self, *args, **kwargs):
4849
4950
5051class QuartStrategy (GinoStrategy ):
51- name = ' quart'
52+ name = " quart"
5253 engine_cls = GinoEngine
5354
5455
@@ -76,6 +77,7 @@ class Gino(_Gino):
7677 connection, so it's not efficient to hold the connection.
7778
7879 """
80+
7981 model_base_classes = _Gino .model_base_classes + (QuartModelMixin ,)
8082 query_executor = GinoExecutor
8183
@@ -85,40 +87,41 @@ def __init__(self, app=None, *args, **kwargs):
8587 self .init_app (app )
8688
8789 def init_app (self , app : Quart ):
88- if app .config .setdefault ('DB_USE_CONNECTION_FOR_REQUEST' , True ):
90+ if app .config .setdefault ("DB_USE_CONNECTION_FOR_REQUEST" , True ):
91+
8992 @app .before_request
9093 async def before_request ():
9194 request .connection = await self .acquire (lazy = True )
9295
9396 @app .after_request
9497 async def after_response (response ):
95- conn = getattr (request , ' connection' , None )
98+ conn = getattr (request , " connection" , None )
9699 if conn is not None :
97100 await conn .release ()
98101 del request .connection
99102 return response
100103
101104 @app .before_first_request
102105 async def before_first_request ():
103- dsn = app .config .get (' DB_DSN' )
106+ dsn = app .config .get (" DB_DSN" )
104107 if not dsn :
105108 dsn = URL (
106- drivername = app .config .setdefault (' DB_DRIVER' , ' asyncpg' ),
107- host = app .config .setdefault (' DB_HOST' , ' localhost' ),
108- port = app .config .setdefault (' DB_PORT' , 5432 ),
109- username = app .config .setdefault (' DB_USER' , ' postgres' ),
110- password = app .config .setdefault (' DB_PASSWORD' , '' ),
111- database = app .config .setdefault (' DB_DATABASE' , ' postgres' ),
109+ drivername = app .config .setdefault (" DB_DRIVER" , " asyncpg" ),
110+ host = app .config .setdefault (" DB_HOST" , " localhost" ),
111+ port = app .config .setdefault (" DB_PORT" , 5432 ),
112+ username = app .config .setdefault (" DB_USER" , " postgres" ),
113+ password = app .config .setdefault (" DB_PASSWORD" , "" ),
114+ database = app .config .setdefault (" DB_DATABASE" , " postgres" ),
112115 )
113116
114117 await self .set_bind (
115118 dsn ,
116- echo = app .config .setdefault (' DB_ECHO' , False ),
117- min_size = app .config .setdefault (' DB_POOL_MIN_SIZE' , 5 ),
118- max_size = app .config .setdefault (' DB_POOL_MAX_SIZE' , 10 ),
119- ssl = app .config .setdefault (' DB_SSL' ),
119+ echo = app .config .setdefault (" DB_ECHO" , False ),
120+ min_size = app .config .setdefault (" DB_POOL_MIN_SIZE" , 5 ),
121+ max_size = app .config .setdefault (" DB_POOL_MAX_SIZE" , 10 ),
122+ ssl = app .config .setdefault (" DB_SSL" ),
120123 loop = asyncio .get_event_loop (),
121- ** app .config .setdefault (' DB_KWARGS' , dict ()),
124+ ** app .config .setdefault (" DB_KWARGS" , dict ()),
122125 )
123126
124127 async def first_or_404 (self , * args , ** kwargs ):
@@ -128,5 +131,5 @@ async def first_or_404(self, *args, **kwargs):
128131 return rv
129132
130133 async def set_bind (self , bind , loop = None , ** kwargs ):
131- kwargs .setdefault (' strategy' , ' quart' )
134+ kwargs .setdefault (" strategy" , " quart" )
132135 return await super ().set_bind (bind , loop = loop , ** kwargs )
0 commit comments