From 1e72bb1e254e31cfba9a21683d24c9daef08d004 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Fri, 26 Apr 2024 19:47:03 -0700 Subject: [PATCH] Update docs --- README.md | 23 ++++++++++++++++++++++- src/DB_Command.php | 22 +++++++++++----------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a0a88377..24552a90 100644 --- a/README.md +++ b/README.md @@ -527,7 +527,7 @@ defined in the SQL. Finds a string in the database. ~~~ -wp db search [...] [--network] [--all-tables-with-prefix] [--all-tables] [--before_context=] [--after_context=] [--regex] [--regex-flags=] [--regex-delimiter=] [--table_column_once] [--one_line] [--matches_only] [--stats] [--table_column_color=] [--id_color=] [--match_color=] +wp db search [...] [--network] [--all-tables-with-prefix] [--all-tables] [--before_context=] [--after_context=] [--regex] [--regex-flags=] [--regex-delimiter=] [--table_column_once] [--one_line] [--matches_only] [--stats] [--table_column_color=] [--id_color=] [--match_color=] [--fields=] [--format=] ~~~ Searches through all of the text columns in a selection of database tables for a given string, Outputs colorized references to the string. @@ -593,6 +593,12 @@ Defaults to searching through all tables registered to $wpdb. On multisite, this [--match_color=] Percent color code to use for the match (unless both before and after context are 0, when no color code is used). For a list of available percent color codes, see below. Default '%3%k' (black on a mustard background). + [--fields=] + Get a specific subset of the fields. + + [--format=] + Render output in a particular format. + The percent color codes available are: | Code | Color @@ -661,6 +667,21 @@ They can be concatenated. For instance, the default match color of black on a mu # SQL search and delete records from database table 'wp_options' where 'option_name' match 'foo' wp db query "DELETE from wp_options where option_id in ($(wp db query "SELECT GROUP_CONCAT(option_id SEPARATOR ',') from wp_options where option_name like '%foo%';" --silent --skip-column-names))" + # Search for a string and print the result as a table + $ wp db search https://localhost:8889 --format=table --fields=table,column,match + +------------+--------------+-----------------------------+ + | table | column | match | + +------------+--------------+-----------------------------+ + | wp_options | option_value | https://localhost:8889 | + | wp_options | option_value | https://localhost:8889 | + | wp_posts | guid | https://localhost:8889/?p=1 | + | wp_users | user_url | 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 + 1 2 + ### wp db tables diff --git a/src/DB_Command.php b/src/DB_Command.php index 3c79ca28..308fe357 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -1208,10 +1208,10 @@ public function prefix() { * : Output the 'table:column' line once before all matching row lines in the table column rather than before each matching row. * * [--one_line] - * : Deprecated: use `--format` instead. Place the 'table:column' output on the same line as the row id and match ('table:column:id:match'). Overrides --table_column_once. + * : Place the 'table:column' output on the same line as the row id and match ('table:column:id:match'). Overrides --table_column_once. * * [--matches_only] - * : Deprecated: use `--format` instead. Only output the string matches (including context). No 'table:column's or row ids are outputted. + * : Only output the string matches (including context). No 'table:column's or row ids are outputted. * * [--stats] * : Output stats on the number of matches found, time taken, tables/columns/rows searched, tables skipped. @@ -1300,15 +1300,15 @@ public function prefix() { * wp db query "DELETE from wp_options where option_id in ($(wp db query "SELECT GROUP_CONCAT(option_id SEPARATOR ',') from wp_options where option_name like '%foo%';" --silent --skip-column-names))" * * # Search for a string and print the result as a table - * $ wp db search https://localhost:8889 --format=table - * +------------+--------------+-----------+-------+-----------------------------+ - * | 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 | - * +------------+--------------+-----------+-------+-----------------------------+ + * $ wp db search https://localhost:8889 --format=table --fields=table,column,match + * +------------+--------------+-----------------------------+ + * | table | column | match | + * +------------+--------------+-----------------------------+ + * | wp_options | option_value | https://localhost:8889 | + * | wp_options | option_value | https://localhost:8889 | + * | wp_posts | guid | https://localhost:8889/?p=1 | + * | wp_users | user_url | 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