-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue type:
[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue
Database system/driver:
[x] cordova
[x] mongodb
[x] mssql
[x] mysql / mariadb
[x] oracle
[x] postgres
[x] sqlite
[x] sqljs
[x] websql
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)
Problem
I've used other ORMs in the past where the debug output for queries are nicely formatted, which vastly improves readability and debugging. Example:
Current debug output looks something like this:
SELECT user.*, photo.* FROM users user JOIN photos photo ON photo.user = user.id AND .isRemoved = FALSE user.name = 'Timber'
Proposed debug output would be something like this:
SELECT USER.*,
photo.*
FROM users USER
INNER JOIN photos photo
ON photo.USER = USER.id
AND photo.isremoved = false
WHERE USER.NAME = 'Timber'
Proposal
I briefly discussed this in gitter a week or so back, and seems like this functionality isn't easily extendable from the current debuggers without making a completely new one. I'd be happy to make a PR for this but not sure what specific solution would work best for the project. Possible options I could foresee are -
- Create a new logger, something like
advanced-console-formattedoradvanced-console-pretty. Can leave default toadvanced-consoleif that makes sense. - Create a new config param (i.e.
debugFormatter) param that takes in a function that all queries will be run through prior to debug output. - Export existing debuggers (i.e.
AdvancedConsoleLogger,SimpleConsoleLogger) so they can be extended. Then users can extend them as they see fit.
Solution
To accomplish the actual formatting, something like sql-formatter would work great. For formatting the NoSQL drivers, could just as easily use one of the many JSON formatting libraries. I don't use NoSQL so I have no idea what the current debug output looks like.
Testing
I also don't see any tests out there for the current debuggers. Is that by design or are they just not able to be tested. Ideally I'd include tests with my PR.
I'd be open to suggestions on any of this. I can also just keep doing what I'm doing with my current project, but would love to see this functionality, or at least the option to format output, in typeorm directly.