-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ab450b0
Added readable ->toSql()
rennokki dc47826
Merge branch 'master' into feature/to-sql
rennokki 6b925dc
Merge branch 'master' into feature/to-sql
rennokki bc093e4
Added toSql test.
rennokki d9f9922
Merge branch 'master' into feature/to-sql
rennokki 1ad945e
updated tests
rennokki ac61d41
Merge branch 'master' into feature/to-sql
rennokki 3577957
Fixed readme conflicts
rennokki 0f4b8a0
Merge branch 'master' into feature/to-sql
rennokki 38526c1
Fix space
rennokki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,19 @@ | |
|
||
class Grammar extends BaseGrammar | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add param doc for argument |
||
*/ | ||
protected function compileWheresToArray($query) | ||
{ | ||
return collect($query->wheres)->map(function ($where) use ($query) { | ||
$baseWhere = $this->{"where{$where['type']}"}($query, $where); | ||
|
||
if (isset($where['sql']) && is_array($where['sql'])) { | ||
$baseWhere = json_encode($baseWhere); | ||
} | ||
|
||
return $where['boolean'].' '.$baseWhere; | ||
})->all(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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
Uh oh!
There was an error while loading. Please reload this page.
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
Example of element of array that function
getQueryLog
returnedThere 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.
@Smolevich @Giacomo92
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 singleget()
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.
@rennokki, do you see this method https://github.com/jenssegers/laravel-mongodb/blob/a8918acadb79f4f90d42eaddf0e996054ddd8184/src/Jenssegers/Mongodb/Query/Builder.php#L413?
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 thegenerateCacheKey
method.