Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Apr 27, 2024
1 parent 531b897 commit 1e72bb1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ defined in the SQL.
Finds a string in the database.

~~~
wp db search <search> [<tables>...] [--network] [--all-tables-with-prefix] [--all-tables] [--before_context=<num>] [--after_context=<num>] [--regex] [--regex-flags=<regex-flags>] [--regex-delimiter=<regex-delimiter>] [--table_column_once] [--one_line] [--matches_only] [--stats] [--table_column_color=<color_code>] [--id_color=<color_code>] [--match_color=<color_code>]
wp db search <search> [<tables>...] [--network] [--all-tables-with-prefix] [--all-tables] [--before_context=<num>] [--after_context=<num>] [--regex] [--regex-flags=<regex-flags>] [--regex-delimiter=<regex-delimiter>] [--table_column_once] [--one_line] [--matches_only] [--stats] [--table_column_color=<color_code>] [--id_color=<color_code>] [--match_color=<color_code>] [--fields=<fields>] [--format=<format>]
~~~

Searches through all of the text columns in a selection of database tables for a given string, Outputs colorized references to the string.
Expand Down Expand Up @@ -593,6 +593,12 @@ Defaults to searching through all tables registered to $wpdb. On multisite, this
[--match_color=<color_code>]
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=<fields>]
Get a specific subset of the fields.

[--format=<format>]
Render output in a particular format.

The percent color codes available are:

| Code | Color
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1e72bb1

Please # to comment.