-
-
Notifications
You must be signed in to change notification settings - Fork 541
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
[5.x] Ability to log fake queries #9695
Merged
jasonvarga
merged 34 commits into
statamic:master
from
JohnathonKoster:adds-stache-query-logging-support
Apr 1, 2024
Merged
[5.x] Ability to log fake queries #9695
jasonvarga
merged 34 commits into
statamic:master
from
JohnathonKoster:adds-stache-query-logging-support
Apr 1, 2024
Conversation
This file contains 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 was referenced Mar 10, 2024
It might be nice if calling |
Uses a real real in-memory sqlite connection. Small price to pay to make it simpler. Remove config option as we'll now always put values into bindings. Now that the QueryExecuted event is populated with more realistic data, bindings are automatically populated within the SQL when using Ray.
- rename trait to fakesqueries - rework to a closure based method that does the timing etc - add to iterator builder - pass table name rather than store, and add methods for figuring out the names - add to iterator builder (e.g. search)
- pass the query into the dumper class instead of a bunch of arguments - use a method on the trait to get all the appropriate wheres etc for the dumper - using that new method, provide the additional where clauses for the entries query that way instead of a "extra from statement" - remove dump trait method in favor of creating a new dumper
…will format to multiline automatically.
… filtering pages etc. move it to just the search query.
…e builders. removed the condition entirely. not sure when there would be no builder.
this allows to avoid the `$this->columns ?? $columns` situation. `$this->columns` will always be what you need. also fixes `$query->get(['col1', 'col2'])` not showing proper `select`ed columns within our fake queries
This was really cool. I couldn't help but make a bunch of tweaks. Now it looks more consistent with what happens with regular Laravel DB/Eloquent queries.
|
jasonvarga
changed the title
[5.x] Adds support for logging Stache queries
[5.x] Adds support for logging fake queries
Apr 1, 2024
jasonvarga
changed the title
[5.x] Adds support for logging fake queries
[5.x] Ability to log fake queries
Apr 1, 2024
jasonvarga
approved these changes
Apr 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Edit by Jason:
It's enabled by default if you have debug enabled. But you can override it and disable it if you want in
config/statamic/system.php
like this now:Queries will show up in Ray or Debugbar just like a regular database query. There's no need to opt into dumping values.
SQLite is now required (only for this fake query feature).
This PR adds the ability to log Stache "queries" like regular database queries. This is disabled by default. It can be configured by setting new configuration values within
config/statamic/stache.php
configuration file:query_logging.enabled
: Determines whether the query logger is enabledquery_logging.dump_values
: Determines whether the query logger will dump "real" values or placeholdersWhen enabled, the query logger will emit Laravel's
Illuminate\Database\Events\QueryExecuted
event. This event will receive a database connection whose closure resolves tonull
, and no bindings.By emitting this event existing tools, like Ray, DebugBar or Telescope will be able to pick up on the executed flat-file queries.
Example with
dump_values
set tofalse
:Example with
dump_values
set totrue
:Important Note: The goal of this feature was not to output perfectly valid SQL statements, but rather to be able to observe what the Stache builders are doing in a familiar way with existing tools.