Skip to content

Commit 60c4773

Browse files
committed
* Kept only release on connection
* And made it a permanent release * Make strategy a real strategy * Finished API docs on engine * Fixing other docs
1 parent e15dfda commit 60c4773

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

gino/ext/sanic.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from ..api import Gino as _Gino, GinoExecutor as _Executor
1111
from ..engine import GinoConnection as _Connection, GinoEngine as _Engine
12+
from ..strategies import GinoStrategy
1213

1314

1415
class SanicModelMixin:
@@ -50,6 +51,14 @@ async def first_or_404(self, *args, **kwargs):
5051
return rv
5152

5253

54+
class SanicStrategy(GinoStrategy):
55+
name = 'sanic'
56+
engine_cls = GinoEngine
57+
58+
59+
SanicStrategy()
60+
61+
5362
# noinspection PyClassHasNoInit
5463
class Gino(_Gino):
5564
"""Support Sanic web server.
@@ -64,7 +73,7 @@ class Gino(_Gino):
6473
pool on response. If you need to release the connection early in the middle
6574
to do some long-running tasks, you can simply do this:
6675
67-
await request['connection'].release()
76+
await request['connection'].release(permanent=False)
6877
6978
Here `request['connection']` is a :class:`LazyConnection` object, see its
7079
doc string for more information.
@@ -89,7 +98,7 @@ async def on_request(request):
8998
async def on_response(request, _):
9099
conn = request.pop('connection', None)
91100
if conn is not None:
92-
await self.release(conn)
101+
await conn.release()
93102

94103
@app.listener('before_server_start')
95104
async def before_server_start(_, loop):
@@ -125,5 +134,5 @@ async def first_or_404(self, *args, **kwargs):
125134
return rv
126135

127136
async def set_bind(self, bind, loop=None, **kwargs):
128-
kwargs.setdefault('engine_cls', GinoEngine)
137+
kwargs.setdefault('strategy', 'sanic')
129138
return await super().set_bind(bind, loop=loop, **kwargs)

0 commit comments

Comments
 (0)