pyramid_debugtoolbar icon indicating copy to clipboard operation
pyramid_debugtoolbar copied to clipboard

Nice to have: reformat SQL code

Open wichert opened this issue 11 years ago • 3 comments

The queries SQLAlchemy produces are a bit hard to read for humans. It might be interesting to optionally use sqlparse to reformat the query.

wichert avatar May 23 '14 07:05 wichert

Generally like this idea.

However this does make scrolling the sqlapanel much much longer. if you use a lot of IN() selects, the current behavior puts each param of the array on a new line. (I just filed a feature request to disable that)

there are a few sqlaparse performance bugs that are unresolved, so I'm wary of integrating it on a large scale.

• https://github.com/andialbrecht/sqlparse/issues/135 • https://github.com/andialbrecht/sqlparse/issues/41

my quick test though made the screen decently better to look at.

sqla.py:

+ import sqlparse

+ def reformat_query(q):
+   return sqlparse.format(q, reindent=True, keyword_case='upper')

                'duration': duration,
-               'statement': stmt,
+               'statement': reformat_query(stmt),
                'parameters': params,

jvanasco avatar Oct 17 '14 20:10 jvanasco

If you look at long queries, most of the space is occupied by the column aliasing. We could truncate/fold the column list, while adding a ... button which would unfold on mouse click.

a3kov avatar May 06 '17 19:05 a3kov

A CSS toggle button could make the page easier to use.

I use a custom module that runs sqlparse and am pretty happy with it as-is though

jvanasco avatar May 06 '17 21:05 jvanasco