dbcli / litecli

CLI for SQLite Databases with auto-completion and syntax highlighting
https://litecli.com
BSD 3-Clause "New" or "Revised" License
2.09k stars 68 forks source link

calling a favorite from within a favorite #101

Open elig0n opened 3 years ago

elig0n commented 3 years ago

I would like to call another favorite from one favorite. i.e.

[favorite_queries]
test = 'SELECT * FROM database WHERE id = "$1"'
test2 = '\f test "$1"'

but I get:

litecli> \f test2 12
unrecognized token: "\"

Can this be done ?

zzl0 commented 3 years ago

Thanks for your feedback. The current design is that the favorite query should be a SQL query.

Could you please explain why you need this? The example above doesn't make sense to me, since you can just run \f test 12 instead. If you want to give it another name, could you copy the SQL and give it a new name?

elig0n commented 3 years ago

That wasn't a very good example indeed. The main need would be to combine & reuse several queries to show up several queries' results all at once.

e.g.

q1 = 'SELECT id FROM database WHERE id = "$1" ' q2 = 'SELECT percentage, (quantity * 8), (distance-6) FROM database WHERE id = "$1" AND owner = "$2" ' ... complex1 = '\f q1 "$1"; \f q2 "$1" "$2"; '

Consider that I have some rather long recursive queries in favorites that I would like to display with some other favorite queries like in the above example so repeatedly typing \f ... ; \f .... ; ...; to see combined results gets tiresome. It would spare typing arguments several times and so on . Yes I can do the concatenations inside the queries themselves and clone queries several time but I thought that this feature can come handy and add to versatility.

zzl0 commented 3 years ago

Thanks for the detailed explanation. I understand why you need this feature, but I hesitate to add it to litecli. It's like introduce variables to the configuration, it may result in complex queries (e.g. the q1 can be a combination of other favorite queries as well). I am not sure if it's worth doing this in litecli, since we can use programming language to implement complex query requirements.

Hi @amjith, what do you think about this feature?

elig0n commented 3 years ago

I thought maybe you can do instead shell-like "aliases" so the entire set of litecli commands can be mixed together and called at once via a nickname. This would allow for example setting a specific table format before viewing a result of a favorite query, or set a custom pager or prompt. i.e: \alias aliasname '\T vertical; \P bat ; \f q1 arg1;'

As of right now using backslash-commands in favorites results in unrecognized token: "\"