Skip to content
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

Add SQL Format Option #93

Closed
hendisantika opened this issue Mar 13, 2023 · 1 comment
Closed

Add SQL Format Option #93

hendisantika opened this issue Mar 13, 2023 · 1 comment

Comments

@hendisantika
Copy link

Add SQL Format Option so that sql log can look feels good.

Like on Spring Boot properties
spring.jpa.properties.hibernate.format_sql=true

Name:dataSource, Connection:7, Time:20, Success:True
Type:Prepared, Batch:False, QuerySize:1, BatchSize:0
Query:["select u1_0.id,u1_0.active,u1_0.confirmation_token,u1_0.email,u1_0.fullname,u1_0.password,u1_0.phone,u1_0.username,u1_1.station_id from user_account u1_0 left join users_station u1_1 on u1_0.id=u1_1.user_id where u1_0.email=?"]
Params:[(user001@yopmail.com)]

It would be better like this:

Name:dataSource, Connection:7, Time:20, Success:True
Type:Prepared, Batch:False, QuerySize:1, BatchSize:0
Query:["
SELECT u1_0.id,
       u1_0.active,
       u1_0.confirmation_token,
       u1_0.email,
       u1_0.fullname,
       u1_0.password,
       u1_0.phone,
       u1_0.username,
       u1_1.station_id
FROM user_account u1_0
         LEFT JOIN users_station u1_1 ON u1_0.id = u1_1.user_id
WHERE u1_0.email=?;
"]
Params:[(user001@yopmail.com)]

Thanks

@ttddyy
Copy link
Member

ttddyy commented Mar 14, 2023

Yes, it is already possible to format output queries.

The Spring Boot property, spring.jpa.properties.hibernate.format_sql delegates the property to Hibernate, and ultimately, Hibernate uses Formatter to format the queries.

Please see the "5.1. Query Logging Listener" section in the documentation. When you scroll down a bit, there is a code snippet that demonstrates the hibernate formatter usage.

Also, the datasource-proxy-examples project has an example code using Hibernate formatter:

@ttddyy ttddyy closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants