db-command icon indicating copy to clipboard operation
db-command copied to clipboard

Output only matching IDs in db search

Open johnbillion opened this issue 5 years ago • 2 comments

When using the wp db search command to search only in a given table (eg. wp_posts), I'd like the output to only contain IDs so I can export them elsewhere without having to extract them from the results which include the matching strings and the context.

Approximately the closest I can get to this is:

wp db search foo wp_posts  --before_context=0 --after_context=0 --one_line

I'd like a flag for the opposite of --matches_only, probably --ids-only.

johnbillion avatar Jan 05 '20 20:01 johnbillion

This seems reasonable.

danielbachhuber avatar Sep 08 '23 18:09 danielbachhuber

We discussed this today during Hack Day. One suggestion to further enhance this is to leverage the formatter (--format) in a backward compatible manner. e.g. --format=ids or --format=matches (the default). The existing --matches_only arg could still be used, hence the backward compatibility. --format=ids with multiple tables doesn't really make sense, so this could be prevented with a warning/error.

swissspidy avatar Nov 10 '23 16:11 swissspidy

@johnbillion @swissspidy Is it still open for working? I can work on this.

i-am-chitti avatar Apr 26 '24 09:04 i-am-chitti

I think so yes :) Feel free to look into it

swissspidy avatar Apr 26 '24 09:04 swissspidy

@i-am-chitti There's a PR at #247. If you'd like to review that it would be helpful. I'm about to take a look myself.

johnbillion avatar Apr 26 '24 11:04 johnbillion