09:22, August 10, 2018
At work, I've built a command-line client program for a number of microservices, which mostly do CRUD operations. I am looking to add search capabilities, but this is not as easy a task as I'd thought.
Let's call this client program boxer, because that's what it's actually named.
So using boxer, one can query a service to return an item in a database. Let's call this a thingy (not what it's really called). Getting a thingy is simple:
boxer get thingy [thing name]
And if we want a list of thingies:
boxer list thingies
With me so far? This is easy stuff. But what if we want to filter that list of thingies? Maybe it looks like this:
boxer list thingies where name = 'monkey' boxer list thingies where name = 'goat' and version = 1
That's a little SQL-like. Or maybe it looks like this:
boxer list thingies --name 'monkey' boxer list thingies --name 'goat' --version 1
But then the client program would have to know the structure of the data at the time it builds the argument parser - this is either really difficult, or involves querying the API for information. Probably not worth doing.
boxer list thingies | jq '.|(select(.name=="monkey"))'
This of course gets messy, and when you have a LOT of data, it's expensive to fetch ALL of it each time you only want a subset. Better to do the filtering at the back-end.
Some things I figure people will commonly search for:
- string 'like' or pattern in a string
- item with an integer field max, as in "the thingy with the highest version"
- item with the most recent date
I've been searching for any sort of "standard" for doing this, but so far I've come up empty. Lots of programs do this kind of thing, but it seems that everyone just re-invents the wheel each time, and there's no consistency.
So I'd be interested in ideas here :)