Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

[Proposal] Add ddSql() and and dumpSql() in query builders. #900

Closed
ajcastro opened this issue Nov 23, 2017 · 1 comment
Closed

[Proposal] Add ddSql() and and dumpSql() in query builders. #900

ajcastro opened this issue Nov 23, 2017 · 1 comment

Comments

@ajcastro
Copy link

ajcastro commented Nov 23, 2017

For easier debugging of queries. Just like collection dumping, but this is for queries. This is actully very useful for long complex queries that you need to copy paste in your sql editor (like sequelpro, dbeaver).

The following code will print their sql queries.

User::where('is_active', 1)
->where('birthdate', '<=', now())
->ddSql() 
->get();

User::where('is_active', 1)
->where('birthdate', '<=', now())
->dumpSql() 
->get()

Also we can incorporate the idea of automatically substituting the binding values instead of question marks. See #901.

First, I am thinking that it can be just simply dd() and dump() but it might be tricky when you accidentally called it after get() and you will be calling the collection's dd() and dump() methods.

Anyway I think this can be achieved in macros and/or scope queries.
It might be better in macros so that you have the option to load macros in service providers and only register them in local environment, not in production.

@ajcastro
Copy link
Author

This is good enough in macros or scope queries.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant