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

FR: support environment variables in (favourite) queries #163

Open
mjpieters opened this issue Sep 16, 2023 · 0 comments
Open

FR: support environment variables in (favourite) queries #163

mjpieters opened this issue Sep 16, 2023 · 0 comments

Comments

@mjpieters
Copy link
Contributor

I'd love to see support for using environment variables in favourite queries, or even in all queries.

The use case is that I have several very similar databases where favourite queries all need to take a parameter to indicate what 'variant' of the database I'm currently using, or I have to copy configuration files for each database file and alter one value in each query filter.

Say, the different values are 'foo' and 'bar', and I have to either do:

favquery1 = '''select ...
    from some_table
    where parameter='$1'
    and other_paramater='$2'
'''
favquery2 = '''select ...
    from some_other_table sot inner join a_third_table att on sot.id = att.sot_id
    where sot.parameter='$1'
    and att.column_name ='$2'
'''

and then run \f favquery1 foo 42 and \f favquery2 bar 45, or I copy the configuration file multiple times and hardcode the parameter in each.

If, instead, I could use environment variables (syntax suggestion, feel free to come up with better syntax, this is based on bash):

favquery1 = '''select ...
    from some_table
    where parameter='${PARAMETER}'
    and other_paramater='$1'
'''
favquery2 = '''select ...
    from some_other_table sot inner join a_third_table att on sot.id = att.sot_id
    where sot.parameter='${PARAMETER}'
    and att.column_name ='$1'
'''

and then start each litecli instance with a different environment variable and use the exact same favourites for each database:

$ PARAMETER=foo litecli foo_database.sqlite
foo_database.sqlite> \f favquery1 42

and

$ PARAMETER=bar litecli bar_database.sqlite
bar_database.sqlite> \f favquery1 42
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

1 participant