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

Add table format option for drush sql:query output #5123

Closed
gitressa opened this issue Apr 14, 2022 · 4 comments
Closed

Add table format option for drush sql:query output #5123

gitressa opened this issue Apr 14, 2022 · 4 comments

Comments

@gitressa
Copy link
Contributor

Is your feature request related to a problem? Please describe.
drush sql:query works well, but for improved readability, is it possible to show the result in table format, showing the column names?

Currently

$ drush sql:query "SELECT table_name AS 'Table', TABLE_ROWS as 'Num. of Rows', round(((data_length + index_length) / 1024 / 1024), 2) 'Size in MB'  FROM information_schema.TABLES where table_schema = 'drupal9' and table_name LIKE 'cache_%'  ORDER BY (data_length + index_length) DESC limit 10;"
cache_1	73	2.55
cache_2	100	1.55
[...]

Would this be possible?

+---------+--------------+------------+
| Table   | Num. of Rows | Size in MB |
+---------+--------------+------------+
| cache_1 | 73           | 2.55       | 
| cache_2 | 100          | 1.55       |
+---------+--------------+------------+

Perhaps by adding a format option like this? drush sql:query --format=table "SELECT table_ ...

@gitressa gitressa changed the title Add drush sql:query format option to output as table? Add drush sql:query table format option for output? Apr 14, 2022
@gitressa gitressa changed the title Add drush sql:query table format option for output? Add table format option for drush sql:query output? Apr 14, 2022
@gitressa gitressa changed the title Add table format option for drush sql:query output? Add table format option to drush sql:query output? Apr 14, 2022
@gitressa gitressa changed the title Add table format option to drush sql:query output? Add table format option for drush sql:query output? Apr 14, 2022
@gitressa gitressa changed the title Add table format option for drush sql:query output? Add table format option for drush sql:query output Apr 14, 2022
@weitzman
Copy link
Member

This does it, on Mysql. I opened a PR to document it. #5124

`drush sql:connect` -e "select * from users limit 5;"

@gitressa
Copy link
Contributor Author

That was fast, thanks!

Lando is challenged with this syntax, though:

$ `drush sql:connect` -e "select * from users limit 5;"

mysql: [Warning] Using a password on the command line interface can be insecure.
'.sql: [ERROR] mysql: unknown option '-

This works, if a bit clunky. Also, it makes it quite hard to use single and double quotes, if needed:

$ lando ssh -c "`drush sql:connect` -e 'select * from users limit 5;'"
+-----+--------------------------------------+----------+
| uid | uuid                                 | langcode |
+-----+--------------------------------------+----------+
|   0 | 52e2ff14-82b5-4e77-9ad1-a99630e00746 | en       |
|   1 | c7f44356-7969-416e-ba7c-f759e0ed5781 | en       |
+-----+--------------------------------------+----------+

Since most Drupal developers are now using Docker-based tools like DDEV or Lando, could a --format=table option for drush sql:query be considered, or is it too much work? I saw an issue earlier (I can't find it now) where you and @greg-1-anderson concluded that formatting MySQL was best left up to MySQL, so I understand if it's not feasible.

@weitzman
Copy link
Member

I sympathize with the clunkiness, but I dont think its Drush's problem to solve. This example is using pretty vanilla bash. FWIW DDEV worked on quoting at ddev/ddev#3603

@gitressa
Copy link
Contributor Author

Thanks for the tip about the DDEV issue, I'll hear Lando if they could consider something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants