This is built into etm4 which, after all, is itself a console script. You can execute queries on the data store by pressing 'q' to open query view. Queries from the current session are stored and you can scroll through the history with the cursor up and down keys, select a query, optionally edit it, and execute it. Results are displayed in a normal etm4 view so that items can be selected, their details displayed and/or modified. The results of the query as displayed can be copied to the system clipboard by pressing Ctrl-C. Frequently used queries can be added to cfg.yaml with shortcuts and then executed in etm using their shortcuts. Tab completion is supported for these shortcuts. One of the advantages of using the built-in query mechanism is that the data store is only loaded once when etm starts and so individual queries do not incur this overhead.
If you want to duplicate or improve on this in your own script, the documentation for queries in
https://tinydb.readthedocs.io/en/latest/index.html might be the best place to start. In etm itself, the ETMQuery class in view.py contains most of the relevant code.
By the way, etm+ is a shell "entry point" provided in the etm4 distribution that you can use to add reminders to the database. E.g., invoking
$ erm+ "the details of a reminder"
or
$ echo " the details of a reminder" | etm+
in a terminal would append the reminder to the file "inbasket.text" in your etm directory. etm iself will display an icon when this file exists to remind you to import it. This file is the default when you press F5 to import a file. The code for this is given by the function "inbasket" in __main__.py.
Please, if you want to continue this discussion, post to
groups.io/g/etm so that others can share.