Named connections
A named connection is a short name for the URL of a database. You type the name in place of the URL, on the command line, with \c and with \copy. A name set with \cset lasts until usql exits. A name in config.yaml is there each time that usql starts.
Name a connection in the session
Section titled “Name a connection in the session”\cset takes a name and a URL:
\cset shelf duckdb:shelf.duckdb\c opens the connection by its name:
\c shelf\cset with no argument lists the names and their URLs. It shows a password in a URL as xxxxx:
sq:books.db=> \csetbooks 'sq:books.db'shelf 'duckdb:shelf.duckdb'\cset with only a name removes that name. usql does not save a name that \cset sets.
Name a connection in config.yaml
Section titled “Name a connection in config.yaml”The connections: section of config.yaml holds the names that usql knows when it starts. Configure usql says where the file is on your system.
connections: books: sq:books.db app: protocol: postgres username: app hostname: localhost port: 5432 database: appA name has a URL, as books has, or a map of the parts of a URL, as app has. usql makes the URL postgres://app@localhost:5432/app from the map of app.
Give the name on the command line in place of the URL:
usql booksKeep the password safe
Section titled “Keep the password safe”config.yaml is a plain text file. If a URL in it holds a password, make sure that only you can read the file. On Linux:
chmod 600 ~/.config/usql/config.yamlOn another system, use the path that \? variables prints.
A driver and its parameters
Section titled “A driver and its parameters”A name can also hold the name of a driver and its parameters, as \c takes them. \cset takes them after the name:
\cset ro sqlite3 file:shop.db?mode=roIn config.yaml, write them as a list:
connections: ro: [sqlite3, "file:shop.db?mode=ro"]Such a name holds no URL, so -W does not work with it. Passwords explains -W.
Use a name with \copy
Section titled “Use a name with \copy”\copy takes a name in place of each URL:
\cset shop sq:shop.db\cset warehouse dk:warehouse.duckdb\copy shop warehouse 'select id, name, price from products' productsCopy data between databases explains \copy.
When a name is also a file
Section titled “When a name is also a file”usql looks for a name before it reads the argument as a path. If a file in the current directory has the same name as a connection, usql opens the connection. To open the file, give a path such as ./books.