Open dynasource opened 7 years ago
Yes. Automatic formatting could be useful.
a similar usecase can be found for the display of database exceptions pages. Where do we want to put the formatting logic?
perhabs formatting by JS with an Asset
I'd prefer to not introduce too much javascript which could interferre with the loaded page so a PHP solution like it is used in apidoc extension can be used: https://github.com/yiisoft/yii2-apidoc/commit/1b5813c4960d9a0a9d9f0d29912c5d578b2da9de
on the contrary, we will have more places in which SQL formatting could be appropiate. This will pollute the core while JS could be unobtrusive.
What about adding class="mysql" to those containers. Then the code would not have to interfere?
How JS could be unobtrusive? It pullutes dependencies and we have a plan to move all JS dependencies out of the core...
class="mysql"
If it's supplied by debug then it should be fine.
how should we integrate it with \yii\db\Exception?https://github.com/yiisoft/yii2/blob/master/framework/db/Schema.php#L635
isnt this a clear case to introduce an Event to the Exception architecture?
Then we can handle all inside the debug extension.
isnt this a clear case to introduce an Event to the Exception architecture?
Isn't it too late to process events when there's an uncaught exception?
I'd introduce $sql property in DB Exception class so it could be obtained.
just by including googles prettifier and some PHP regex
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
we can get this:
Do we like this?
👎 It might look better.
@alexraputa any proposals?
Just compare this to real formatters: http://www.dpriver.com/products/sqlpp/sqlexamples2.php
@rob006, 👍 it looks much better.
Just compare this to real formatters: http://www.dpriver.com/products/sqlpp/sqlexamples2.php
this is a paid one? http://www.dpriver.com/buynow.php
It would be nice to have use an open source library for this. This can be time consuming to create yourself.
First result from google: https://github.com/jdorn/sql-formatter
jdorn looks nice indeed. A nice example at http://jdorn.github.io/sql-formatter/
Unless people have better proposals, I'll integrate that one.
I've looked into the Sql formatters. It seems that 'jdorn/sql-formatter' has the most stars on github and from what I have seen, also the most readable output.
It has one disadvantage though. Readability goes at cost of the length of the page. Should I integrate a 'onclick' prettify toggle?
Length doesn't matter in debug mode.
well, having many of these page filling queries is quite obtrusive. People have to expect another userexperience on the DB debug panel
Won't matter much.
it matters on a 30 inch ;)
It has one disadvantage though. Readability goes at cost of the length of the page. Should I integrate a 'onclick' prettify toggle?
That would be good to have otherwise scrolling through a lot of querys is tedious when they are complex.
The toggle should be sticky then. Its state should survive page reloads.
status update: jdorn/sql-formatter does not to seem to be stable and gives errors with certain SQL's. This is not desired behavior for inclusion.
@dynasource worth reporting to jdorn/sql-formatter
issues...
I'm questioning to keep it simple instead of having a library to fix it. On the other hand, perhabs we should adopt flexibility and make the developer to decide which sql formatter he should use
Well, reporting it is a good idea anyways.
Some degree of flexibility is good.
this deserves attention regarding readability. Having 1 line of SQL is not really practical.