9
9
10
10
from ..api import Gino as _Gino , GinoExecutor as _Executor
11
11
from ..engine import GinoConnection as _Connection , GinoEngine as _Engine
12
+ from ..strategies import GinoStrategy
12
13
13
14
14
15
class SanicModelMixin :
@@ -50,6 +51,14 @@ async def first_or_404(self, *args, **kwargs):
50
51
return rv
51
52
52
53
54
+ class SanicStrategy (GinoStrategy ):
55
+ name = 'sanic'
56
+ engine_cls = GinoEngine
57
+
58
+
59
+ SanicStrategy ()
60
+
61
+
53
62
# noinspection PyClassHasNoInit
54
63
class Gino (_Gino ):
55
64
"""Support Sanic web server.
@@ -64,7 +73,7 @@ class Gino(_Gino):
64
73
pool on response. If you need to release the connection early in the middle
65
74
to do some long-running tasks, you can simply do this:
66
75
67
- await request['connection'].release()
76
+ await request['connection'].release(permanent=False )
68
77
69
78
Here `request['connection']` is a :class:`LazyConnection` object, see its
70
79
doc string for more information.
@@ -89,7 +98,7 @@ async def on_request(request):
89
98
async def on_response (request , _ ):
90
99
conn = request .pop ('connection' , None )
91
100
if conn is not None :
92
- await self .release (conn )
101
+ await conn .release ()
93
102
94
103
@app .listener ('before_server_start' )
95
104
async def before_server_start (_ , loop ):
@@ -125,5 +134,5 @@ async def first_or_404(self, *args, **kwargs):
125
134
return rv
126
135
127
136
async def set_bind (self , bind , loop = None , ** kwargs ):
128
- kwargs .setdefault ('engine_cls ' , GinoEngine )
137
+ kwargs .setdefault ('strategy ' , 'sanic' )
129
138
return await super ().set_bind (bind , loop = loop , ** kwargs )
0 commit comments