Skip to content
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

Better document --skip-column-names for retrieving a specific value #249

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ wp db query [<sql>] [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [-
Executes an arbitrary SQL query using `DB_HOST`, `DB_NAME`, `DB_USER`
and `DB_PASSWORD` database credentials specified in wp-config.php.

Use the `--skip-column-names` MySQL argument to exclude the headers
from a SELECT query. Pipe the output to remove the ASCII table
entirely.

**OPTIONS**

[<sql>]
Expand All @@ -364,6 +368,12 @@ Executes an arbitrary SQL query using `DB_HOST`, `DB_NAME`, `DB_USER`
# Execute a query stored in a file
$ wp db query < debug.sql

# Query for a specific value in the database (pipe the result to remove the ASCII table borders)
$ wp db query 'SELECT option_value FROM wp_options WHERE option_name="home"' --skip-column-names
+---------------------+
| https://example.com |
+---------------------+

# Check all tables in the database
$ wp db query "CHECK TABLE $(wp db tables | paste -s -d, -);"
+---------------------------------------+-------+----------+----------+
Expand Down
10 changes: 10 additions & 0 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ public function cli( $_, $assoc_args ) {
* Executes an arbitrary SQL query using `DB_HOST`, `DB_NAME`, `DB_USER`
* and `DB_PASSWORD` database credentials specified in wp-config.php.
*
* Use the `--skip-column-names` MySQL argument to exclude the headers
* from a SELECT query. Pipe the output to remove the ASCII table
* entirely.
*
* ## OPTIONS
*
* [<sql>]
Expand All @@ -423,6 +427,12 @@ public function cli( $_, $assoc_args ) {
* # Execute a query stored in a file
* $ wp db query < debug.sql
*
* # Query for a specific value in the database (pipe the result to remove the ASCII table borders)
* $ wp db query 'SELECT option_value FROM wp_options WHERE option_name="home"' --skip-column-names
* +---------------------+
* | https://example.com |
* +---------------------+
*
* # Check all tables in the database
* $ wp db query "CHECK TABLE $(wp db tables | paste -s -d, -);"
* +---------------------------------------+-------+----------+----------+
Expand Down