Closed petenelson closed 2 years ago
At first I thought this PR was good for merging, but then I realized that it deviates considerably from #145 .
I think this should be implemented as a [--format=<format>]
flag to the existing wp db query
:
mysql
directly, not loading WP for this.--format=<format>
from the arguments that are sent to mysql
select
queries when --format=<format>
was specifiedmysql
and then pass them to the requested formatterAre you up for another stab at this?
This was the part I'm not quite clear on how to implement collect results from mysql and then pass them to the requested formatter
which is why I went with this get-rows route. Would the ob_start/ob_get_clean pickup the terminal output from the run_mysql_command()
function?
Aha, think I found what's needed, passing descriptors and reading from pipes. Making some progress on this.
Something like this, but it will take an update to the run_mysql_command()
in Utils in order to pass an arg to be able to capture the output.
$descriptors = [
[ 'pipe', 'r' ],
[ 'pipe', 'w' ],
[ 'pipe', 'w' ],
];
$run_args = [ 'return_results' => true ];
$results = self::run( '/usr/bin/env mysql --no-defaults --no-auto-rehash --skip-column-names', $assoc_args, $descriptors, $run_args );
$results = array_filter( explode( PHP_EOL, $results ) );
I'll need to get the main wp-cli project setup locally for development in order to submit a PR for the run_mysql_command() update.
@petenelson Looks like you've got ti figured out. Let me know if you need assistance with building something like the above.
This will be greatly simplified by https://github.com/wp-cli/wp-cli/pull/5384.
@petenelson Are you still interested in working on this?
It should be more straight-forward now, I've adapted Utils\ run_mysql_command()
, so that if you pass false
as the fourth argument, it will return an array with [ $stdout, $sterr, $exit_code ]
.
Hey @petenelson,
Gentle ping to see if you're still up for giving this another try...
No worries at all if you can't find the time or energy, I would just appreciate knowing about that to decide what to do with the PR.
Probably not right now. I'd need to get all of the development environment up and running again.
Proceeding with https://github.com/wp-cli/wp-cli/issues/5594 for this repository. I've captured this PR to https://gist.github.com/danielbachhuber/6924f9d9aa78fa3b2092943943bf45b7 in case this PR is auto-closed or broken in some way.
This code addresses #145 by adding a
get-rows
command to allow custom DB queries to get results formatted in a list, CSV, JSON, or a single column that can be piped to other commands.