xo / usql

Universal command-line interface for SQL databases
MIT License
8.81k stars 346 forks source link

feature: connection aliases #443

Closed rjbudzynski closed 3 months ago

rjbudzynski commented 4 months ago

It would be very convenient to be able to define an alias for the set of connection data (protocol. host, port, username, password, database) and connect via this alias instead of typing the whole deal every time. If I understand correctly, the .usqlpass functionality only allows one to omit the password.

Such functionality is for instance available in the similar "henplus" utility, written in java. But that one is old and no longer maintained, and I found usql when searching for a replacement.

kenshaw commented 4 months ago

@rjbudzynski this has been requested more than once, and I have an overhaul coming that will add this functionality. In the interim, you can use variables, and set them in your .usqlrc:

$ cat ~/.usqlrc
\set MYURL postgres://user:pass@host
$ usql
Type "help" for help.

(not connected)=> \c :MYURL
error: pq: dial tcp: lookup host: no such host
(not connected)=> \echo :MYURL
postgres://user:pass@host
(not connected)=>
rjbudzynski commented 4 months ago

Thank you, very nice hint.

kenshaw commented 3 months ago

This is almost finished, and will be in the next major release.

kenshaw commented 3 months ago

This has been implemented.