3

I'm trying to understand how can I "pretty" format the below traced DB statement sqlx gives me using tracing:

2023-08-01T15:54:42.675396Z DEBUG sqlx::query:117: summary: "SELECT \"user\".* FROM \"user\" …", db.statement: "\n\nSELECT\n  \"user\".*\nFROM\n  \"user\"\nWHERE\n  \"user\".\"id\" = $1\n", rows_affected: 0, rows_returned: 1, elapsed: 2.8366ms

Is there a way to have something like the below instead?

SELECT "user".* FROM "user" WHERE "user"."id" = '1'

I need this when something is broken and I need to debug. I'm using debug level in this case in fact.

Caesar
  • 6,733
  • 4
  • 38
  • 44
Fred Hors
  • 3,258
  • 3
  • 25
  • 71
  • Apparently not. There's a similar open GitHub issue [here](https://github.com/launchbadge/sqlx/issues/2532), which is unanswered. – OfirD Aug 08 '23 at 19:37
  • I'm a bit confused: are you interested in changing how sqlx formats its logs? or are you interested in printing the SQL yourself? – kmdreko Aug 08 '23 at 20:00
  • @kmdreko, thanks for the answer: I need to see the SQL I send to postgres. Because I need to understand what is going on. – Fred Hors Aug 08 '23 at 20:39
  • I understand seeing the SQL is valuable, but you didn't answer my question: are you trying to modify how sqlx formats its logs into something more succinct? or are you able to add your own output? or are you trying to parse sqlx's log format? – kmdreko Aug 08 '23 at 21:53
  • @kmdreko I don't know what is the better way, what can you suggest? – Fred Hors Aug 08 '23 at 21:55
  • It sounds like you just want [`.sql()`](https://docs.rs/sqlx/latest/sqlx/macro.query.html?search=sql) which is available on almost anything in sqlx that you could hope for. But its really hard to know what you're expecting since the question seems pretty focused on the log format. – kmdreko Aug 08 '23 at 21:59
  • @kmdreko, yes. I need a way to set for example `debug` level and see the query in a good format and with the parameters visible. – Fred Hors Aug 08 '23 at 22:11
  • @OfirD The issue seems to suggest that the parameters are inserted in the string, OP's example contains a `$1` he would like to have resolved. So I don't think this issue matches. – Finomnis Aug 14 '23 at 05:49
  • @FredHors Please provide a [MRE] for us to play around with. I don't think this question is easily answerable without having code. Please write a `main` with something like sqlite that actually produces this log output. – Finomnis Aug 14 '23 at 05:51

0 Answers0