-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging SQL #939
Comments
Printing the actual query sounds better. I've often generated some SQL with an ORM and then pasted it into a MySQL/Postgres console, especially to run EXPLAIN on the query. |
Avoids escaping the SQL code for easier reading
I've just pushed a commit to the persistent repo to address this. I haven't tested it myself in the scaffolding, but it should work as expected. @andrewthad if you can give this a go and let me know if it addresses your concern, I can release to Hackage. |
I don't have an easy way to run it right now, but from looking at your commit I can tell that it does what I want. If you're ok with releasing it without me running it, then you could go ahead with that, but if you'd rather have someone check it, then I can do that that sometime tomorrow. |
I'm fine waiting another day or two before releasing. |
I just tried it out and it works. The only other thing I'll mention (because I just noticed this) is that the bit at the end that shows the source file containing the code that called the logger seems like it's sort of a waste, especially given that (1) all sql logs originate here and (2) None of the other server logs that yesod creates have source file information. But I'm content with it as is if that's not something you want to do. Here is the output I get from your a scaffolded site with your latest commit:
|
Changing that location thing would be more invasive than it would seem, and would actually break a very useful feature: try using I'll release this to Hackage now, thanks for checking it! |
I wasn't suggesting that we redefine |
Oh, that's a good idea, I hadn't thought of doing so. Let me test that out On Tue Feb 24 2015 at 6:45:24 PM andrewthad notifications@github.com
|
Done :) |
Sweet. Thanks for getting that in. |
With the scaffolded yesod site, the log output for SQL queries looks like this:
I have truncated the line because it is very long. However, my point is that is it a Haskell-escaped string. This would be great if I was planning on sticking it in GHCi to replay the query, but I never do that. Moreover, I feel pretty confident that almost no one is doing that. I open up psql and copy the queries into that (after having to run a script to unescape C-style strings). It would be nice if the logs just printed the actual query. I'd like to see either one of two things:
The line causing this behavior is right here: https://hackage.haskell.org/package/persistent-2.1.1.4/docs/src/Database-Persist-Sql-Raw.html#rawSql
In the definition of
rawQueryRes
where we callshow sql
. Thanks for any feedback or consideration of this proposal.The text was updated successfully, but these errors were encountered: