@@ -13,7 +13,7 @@ async def get_or_404(cls, *args, **kwargs):
1313 # noinspection PyUnresolvedReferences
1414 rv = await cls .get (* args , ** kwargs )
1515 if rv is None :
16- raise NotFound (' {} is not found' .format (cls .__name__ ))
16+ raise NotFound (" {} is not found" .format (cls .__name__ ))
1717 return rv
1818
1919
@@ -22,7 +22,7 @@ class GinoExecutor(_Executor):
2222 async def first_or_404 (self , * args , ** kwargs ):
2323 rv = await self .first (* args , ** kwargs )
2424 if rv is None :
25- raise NotFound (' No such data' )
25+ raise NotFound (" No such data" )
2626 return rv
2727
2828
@@ -31,7 +31,7 @@ class GinoConnection(_Connection):
3131 async def first_or_404 (self , * args , ** kwargs ):
3232 rv = await self .first (* args , ** kwargs )
3333 if rv is None :
34- raise NotFound (' No such data' )
34+ raise NotFound (" No such data" )
3535 return rv
3636
3737
@@ -42,12 +42,12 @@ class GinoEngine(_Engine):
4242 async def first_or_404 (self , * args , ** kwargs ):
4343 rv = await self .first (* args , ** kwargs )
4444 if rv is None :
45- raise NotFound (' No such data' )
45+ raise NotFound (" No such data" )
4646 return rv
4747
4848
4949class SanicStrategy (GinoStrategy ):
50- name = ' sanic'
50+ name = " sanic"
5151 engine_cls = GinoEngine
5252
5353
@@ -72,6 +72,7 @@ class Gino(_Gino):
7272 await request['connection'].release(permanent=False)
7373
7474 """
75+
7576 model_base_classes = _Gino .model_base_classes + (SanicModelMixin ,)
7677 query_executor = GinoExecutor
7778
@@ -81,58 +82,59 @@ def __init__(self, app=None, *args, **kwargs):
8182 self .init_app (app )
8283
8384 def init_app (self , app ):
84- if app .config .setdefault ('DB_USE_CONNECTION_FOR_REQUEST' , True ):
85- @app .middleware ('request' )
85+ if app .config .setdefault ("DB_USE_CONNECTION_FOR_REQUEST" , True ):
86+
87+ @app .middleware ("request" )
8688 async def on_request (request ):
8789 conn = await self .acquire (lazy = True )
88- if hasattr (request , ' ctx' ):
90+ if hasattr (request , " ctx" ):
8991 request .ctx .connection = conn
9092 else :
91- request [' connection' ] = conn
93+ request [" connection" ] = conn
9294
93- @app .middleware (' response' )
95+ @app .middleware (" response" )
9496 async def on_response (request , _ ):
95- if hasattr (request , ' ctx' ):
96- conn = getattr (request .ctx , ' connection' , None )
97+ if hasattr (request , " ctx" ):
98+ conn = getattr (request .ctx , " connection" , None )
9799 else :
98- conn = request .pop (' connection' , None )
100+ conn = request .pop (" connection" , None )
99101 if conn is not None :
100102 await conn .release ()
101103
102- @app .listener (' after_server_start' )
104+ @app .listener (" after_server_start" )
103105 async def before_server_start (_ , loop ):
104- if app .config .get (' DB_DSN' ):
106+ if app .config .get (" DB_DSN" ):
105107 dsn = app .config .DB_DSN
106108 else :
107109 dsn = URL (
108- drivername = app .config .setdefault (' DB_DRIVER' , ' asyncpg' ),
109- host = app .config .setdefault (' DB_HOST' , ' localhost' ),
110- port = app .config .setdefault (' DB_PORT' , 5432 ),
111- username = app .config .setdefault (' DB_USER' , ' postgres' ),
112- password = app .config .setdefault (' DB_PASSWORD' , '' ),
113- database = app .config .setdefault (' DB_DATABASE' , ' postgres' ),
110+ drivername = app .config .setdefault (" DB_DRIVER" , " asyncpg" ),
111+ host = app .config .setdefault (" DB_HOST" , " localhost" ),
112+ port = app .config .setdefault (" DB_PORT" , 5432 ),
113+ username = app .config .setdefault (" DB_USER" , " postgres" ),
114+ password = app .config .setdefault (" DB_PASSWORD" , "" ),
115+ database = app .config .setdefault (" DB_DATABASE" , " postgres" ),
114116 )
115117
116118 await self .set_bind (
117119 dsn ,
118- echo = app .config .setdefault (' DB_ECHO' , False ),
119- min_size = app .config .setdefault (' DB_POOL_MIN_SIZE' , 5 ),
120- max_size = app .config .setdefault (' DB_POOL_MAX_SIZE' , 10 ),
121- ssl = app .config .setdefault (' DB_SSL' ),
120+ echo = app .config .setdefault (" DB_ECHO" , False ),
121+ min_size = app .config .setdefault (" DB_POOL_MIN_SIZE" , 5 ),
122+ max_size = app .config .setdefault (" DB_POOL_MAX_SIZE" , 10 ),
123+ ssl = app .config .setdefault (" DB_SSL" ),
122124 loop = loop ,
123- ** app .config .setdefault (' DB_KWARGS' , dict ()),
125+ ** app .config .setdefault (" DB_KWARGS" , dict ()),
124126 )
125127
126- @app .listener (' before_server_stop' )
128+ @app .listener (" before_server_stop" )
127129 async def after_server_stop (_ , loop ):
128130 await self .pop_bind ().close ()
129131
130132 async def first_or_404 (self , * args , ** kwargs ):
131133 rv = await self .first (* args , ** kwargs )
132134 if rv is None :
133- raise NotFound (' No such data' )
135+ raise NotFound (" No such data" )
134136 return rv
135137
136138 async def set_bind (self , bind , loop = None , ** kwargs ):
137- kwargs .setdefault (' strategy' , ' sanic' )
139+ kwargs .setdefault (" strategy" , " sanic" )
138140 return await super ().set_bind (bind , loop = loop , ** kwargs )
0 commit comments