Skip to content

Commit

Permalink
Merge pull request #249 from wp-cli/248-skip-column-names
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy authored Nov 13, 2023
2 parents bda6405 + 694ed4b commit eea28dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit eea28dd

Please sign in to comment.