-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[feature] Added ->toSql() for raw wheres #1916
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
Conversation
Tests are failing due to Coveralls. This might be needed to PR before re-checking the tests: #1922 |
README.md
Outdated
@@ -17,6 +17,7 @@ Table of contents | |||
* [Eloquent](#eloquent) | |||
* [Optional: Alias](#optional-alias) | |||
* [Query Builder](#query-builder) | |||
* [`toSql()`](#to-sql) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can put this under a category called "debugging" or "inspecting queries".
If I remember correctly there was also a way to get the mongodb query. That could also fit under that category. Will also be nice to be able to send this link to people having issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add else info about DB::getQueryLog()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It old feature but getQueryLog() return original query struncture to mongodb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jenssegers maybe fix this after #1917
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Smolevich i will look into it as soon as i get home
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rennokki what about to add info about using DB::getQueryLog()
For example
DB::enableQueryLog();
$user = factory(User::class)->create();
$query = DB::connection()->table(config('auth.passwords.users.table'));
dd(DB::getQueryLog());
Example of element of array that function getQueryLog
returned
0 => array:3 [
"query" => "users.insertOne({"name":"Mr. Jayden Cremin Sr.","email":"[email protected]","email_verified_at":{"$date":{"$numberLong":"1579992655000"}},"password":"$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC\/.og\/at2.uheWG\/igi","remember_token":"r6HicH5d78","updated_at":{"$date":{"$numberLong":"1579992655901"}},"created_at":{"$date":{"$numberLong":"1579992655901"}}})"
"bindings" => []
"time" => 48.52
]
1 => array:3 [
"query" => "users.find({"email":"[email protected]"},{"limit":1,"typeMap":{"root":"array","document":"array"}})"
"bindings" => []
"time" => 4.49
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scope of this PR was to be able to get the query string before the actual query was executed, so i can be able to add cache query-by-query.
I can add the query log thing in the readme, because that's useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far, the single issue here is that the basic get()
and the aggregate and groups are treated differently. This means that the final query is split into two methods rather than a single get()
one.
I repeat - the purpose of this PR was to get the string for each query, so I can be able to query the cache query-by-query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Smolevich I think $options
and $pipeline
has to be attributes in the class and be passed to the generateCacheKey
method.
@@ -6,4 +6,19 @@ | |||
|
|||
class Grammar extends BaseGrammar | |||
{ | |||
/** | |||
* {@inheritdoc} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add param doc for argument $query
and for return type please
@rennokki please resolve conflcts |
@rennokki this has been open for almost a month, will you take care? Looks like no as you've deleted forked repo while at the same trying to reinvent a wheel. Good luck, closing. |
See this open PR i closed a while: #1887
It's good to make it work not only because of debugging (either it's not called SQL), but also you can cache query-by-query easier using packages like this: https://github.com/rennokki/laravel-eloquent-query-cache
Needs testing.Actually it is safe, it detects arrays and automatically serializes them to string, which is exactly what's needed.