Skip to content

Commit 9f59093

Browse files
committed
Added DB_ECHO option for SQLAlchemy echo mode
1 parent ceaa811 commit 9f59093

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

docs/sanic.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Supported configurations:
2222
- DB_USER
2323
- DB_PASSWORD
2424
- DB_DATABASE
25+
- DB_ECHO
2526
- DB_POOL_MIN_SIZE
2627
- DB_POOL_MAX_SIZE
2728
- DB_USE_CONNECTION_FOR_REQUEST
@@ -75,6 +76,7 @@ To integrate with Sanic, a few configurations needs to be set in
7576
- DB_USER: if not set, ``postgres``
7677
- DB_PASSWORD: if not set, empty string
7778
- DB_DATABASE: if not set, ``postgres``
79+
- DB_ECHO: if not set, ``False``
7880
- DB_POOL_MIN_SIZE: if not set, 5
7981
- DB_POOL_MAX_SIZE: if not set, 10
8082

gino/ext/aiohttp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class Gino(_Gino):
8686
will replace all previous connect arguments.
8787
* ``pool_min_size`` - the initial number of connections of the db pool.
8888
* ``pool_max_size`` - the maximum number of connections in the db pool.
89+
* ``echo`` - enable SQLAlchemy echo mode.
8990
9091
If the ``db`` is set as an aiohttp middleware, then a lazy connection is
9192
available at ``request['connection']``. By default, a database connection
@@ -136,6 +137,7 @@ async def before_server_start(app_):
136137

137138
await self.set_bind(
138139
dsn,
140+
echo=config.setdefault('echo', False),
139141
min_size=config.setdefault('pool_min_size', 5),
140142
max_size=config.setdefault('pool_max_size', 10),
141143
loop=app_.loop,

gino/ext/quart.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ async def before_first_request():
124124

125125
await self.set_bind(
126126
dsn,
127+
echo=app.config.setdefault('DB_ECHO', False),
127128
min_size=app.config.setdefault('DB_POOL_MIN_SIZE', 5),
128129
max_size=app.config.setdefault('DB_POOL_MAX_SIZE', 10),
129130
loop=asyncio.get_event_loop(),

gino/ext/sanic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ async def before_server_start(_, loop):
119119

120120
await self.set_bind(
121121
dsn,
122+
echo=app.config.setdefault('DB_ECHO', False),
122123
min_size=app.config.setdefault('DB_POOL_MIN_SIZE', 5),
123124
max_size=app.config.setdefault('DB_POOL_MAX_SIZE', 10),
124125
loop=loop,

gino/ext/tornado.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
- ``'db_user'`` -- if not set, ``postgres``;
6464
- ``'db_password'`` -- if not set, empty string;
6565
- ``'db_database'`` -- if not set, ``postgres``;
66+
- ``'db_echo'`` -- whether to enable SQLAlchemy echo mode, defaults to False.
6667
- ``dsn`` -- a SQLAlchemy database URL to create the engine, its existence
6768
will replace all previous connect arguments.
6869
- ``'db_pool_min_size'`` -- number of connection the pool will be initialized
@@ -187,6 +188,7 @@ def inner(value):
187188
_define('db_user', 'postgres', str, group='database')
188189
_define('db_password', 'password', str, group='database')
189190
_define('db_database', 'postgres', str, group='database')
191+
_define('db_echo', False, bool, group='database')
190192
_define('db_pool_min_size', 5, int, group='database',
191193
callback=_assert_not_negative('db_pool_min_size'))
192194
_define('db_pool_max_size', 10, int, group='database',
@@ -341,6 +343,7 @@ async def late_init(self, db: Gino, *, loop=None, options=_options):
341343

342344
await db.set_bind(
343345
dsn,
346+
echo=options['db_echo'],
344347
min_size=options['db_pool_min_size'],
345348
max_size=options['db_pool_max_size'],
346349
max_inactive_connection_lifetime=(

0 commit comments

Comments
 (0)