Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use value instead of ID for the primary key column
  • Loading branch information
2ndkauboy committed Apr 26, 2024
commit 1c9b2e862d578d37a6505c4f0b4aee2029f78c15
22 changes: 11 additions & 11 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1301,14 +1301,14 @@ public function prefix() {
*
* # Search for a string and print the result as a table
* $ wp db search https://localhost:8889 --format=table
* +------------+--------------+-----------+----+-----------------------------+
* | table | column | key | ID | match |
* +------------+--------------+-----------+----+-----------------------------+
* | wp_options | option_value | option_id | 1 | https://localhost:8889 |
* | wp_options | option_value | option_id | 2 | https://localhost:8889 |
* | wp_posts | guid | ID | 1 | https://localhost:8889/?p=1 |
* | wp_users | user_url | ID | 1 | https://localhost:8889 |
* +------------+--------------+-----------+----+-----------------------------+
* +------------+--------------+-----------+-------+-----------------------------+
* | table | column | key | value | match |
* +------------+--------------+-----------+-------+-----------------------------+
* | wp_options | option_value | option_id | 1 | https://localhost:8889 |
* | wp_options | option_value | option_id | 2 | https://localhost:8889 |
* | wp_posts | guid | ID | 1 | https://localhost:8889/?p=1 |
* | wp_users | user_url | ID | 1 | https://localhost:8889 |
* +------------+--------------+-----------+-------+-----------------------------+
*
* # Search for a string and get only the IDs (only works for a single table)
* $ wp db search https://localhost:8889 wp_options --format=ids
Expand Down Expand Up @@ -1487,7 +1487,7 @@ public function search( $args, $assoc_args ) {
'table' => $table,
'column' => $column,
'key' => $primary_key,
'ID' => $result->$primary_key,
'value' => $result->$primary_key,
// Remove the colors for the format output.
'match' => str_replace( [ $colors['match'][0], $colors['match'][1] ], [ '', '' ], $col_val ),
];
Expand All @@ -1504,7 +1504,7 @@ public function search( $args, $assoc_args ) {
$formatter_args = [
'format' => $format,
];
$formatter_fields = [ 'table', 'column', 'key', 'ID', 'match' ];
$formatter_fields = [ 'table', 'column', 'key', 'value', 'match' ];

if ( $fields ) {
$fields = explode( ',', $assoc_args['fields'] );
Expand All @@ -1515,7 +1515,7 @@ public function search( $args, $assoc_args ) {
if ( count( $tables ) > 1 ) {
WP_CLI::error( 'The "ids" format can only be used for a single table.' );
}
$search_results = array_column( $search_results, 'ID' );
$search_results = array_column( $search_results, 'value' );
}

$formatter = new Formatter( $formatter_args, $formatter_fields );
Expand Down