File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -64,19 +64,18 @@ class Gino(_Gino):
64
64
"""Support Sanic web server.
65
65
66
66
By :meth:`init_app` GINO registers a few hooks on Sanic, so that GINO could
67
- use database configuration in Sanic `config` to initialize the bound pool.
67
+ use database configuration in Sanic ``config`` to initialize the bound
68
+ engine.
68
69
69
70
A lazy connection context is enabled by default for every request. You can
70
- change this default behavior by setting `DB_USE_CONNECTION_FOR_REQUEST`
71
- config value to `False`. By default, a database connection is borrowed on
71
+ change this default behavior by setting `` DB_USE_CONNECTION_FOR_REQUEST` `
72
+ config value to `` False` `. By default, a database connection is borrowed on
72
73
the first query, shared in the same execution context, and returned to the
73
74
pool on response. If you need to release the connection early in the middle
74
- to do some long-running tasks, you can simply do this:
75
+ to do some long-running tasks, you can simply do this::
75
76
76
77
await request['connection'].release(permanent=False)
77
78
78
- Here `request['connection']` is a :class:`LazyConnection` object, see its
79
- doc string for more information.
80
79
"""
81
80
model_base_classes = _Gino .model_base_classes + (SanicModelMixin ,)
82
81
query_executor = GinoExecutor
Original file line number Diff line number Diff line change @@ -31,7 +31,21 @@ async def root(request):
31
31
32
32
@app .route ('/users/<uid:int>' )
33
33
async def get_user (request , uid ):
34
- return json ((await User .get_or_404 (uid )).to_dict ())
34
+ method = request .args .get ('method' )
35
+ q = User .query .where (User .id == uid )
36
+ if method == '1' :
37
+ return json ((await q .gino .first_or_404 ()).to_dict ())
38
+ elif method == '2' :
39
+ return json (
40
+ (await request ['connection' ].first_or_404 (q )).to_dict ())
41
+ elif method == '3' :
42
+ return json (
43
+ (await db .bind .first_or_404 (q )).to_dict ())
44
+ elif method == '4' :
45
+ return json (
46
+ (await db .first_or_404 (q )).to_dict ())
47
+ else :
48
+ return json ((await User .get_or_404 (uid )).to_dict ())
35
49
36
50
@app .route ('/users' , methods = ['POST' ])
37
51
async def add_user (request ):
@@ -63,6 +77,10 @@ def test(app):
63
77
request , response = app .test_client .get ('/users/1' )
64
78
assert response .status == 404
65
79
80
+ for method in '1234' :
81
+ request , response = app .test_client .get (f'/users/1?method={ method } ' )
82
+ assert response .status == 404
83
+
66
84
request , response = app .test_client .post ('/users' ,
67
85
data = dict (name = 'fantix' ))
68
86
assert response .status == 200
You can’t perform that action at this time.
0 commit comments