diff --git a/technology/applications/Applications.md b/technology/applications/Applications.md index 0cec095..36d6fe3 100644 --- a/technology/applications/Applications.md +++ b/technology/applications/Applications.md @@ -1,6 +1,6 @@ --- obj: meta/collection -rev: 2024-07-14 +rev: 2024-12-10 --- # Applications @@ -262,6 +262,7 @@ rev: 2024-07-14 - [Docker](../tools/Docker.md) - [Podman](../tools/Podman.md) - [serie](./cli/serie.md) +- [usql](./cli/usql.md) ## Media - [yt-dlp](./media/yt-dlp.md) diff --git a/technology/applications/cli/usql.md b/technology/applications/cli/usql.md new file mode 100644 index 0000000..c648374 --- /dev/null +++ b/technology/applications/cli/usql.md @@ -0,0 +1,229 @@ +--- +obj: application +repo: https://github.com/xo/usql +rev: 2024-12-10 +--- + +# usql +usql is a universal command-line interface for PostgreSQL, MySQL, Oracle Database, SQLite3, Microsoft SQL Server, and many other databases including NoSQL and non-relational databases! + +usql provides a simple way to work with SQL and NoSQL databases via a command-line inspired by PostgreSQL's psql. usql supports most of the core psql features, such as variables, backticks, backslash commands and has additional features that psql does not, such as multiple database support, copying between databases, syntax highlighting, context-based completion, and terminal graphics. + +## Usage + +```sh +usql [options]... [DSN] +``` + +DSN can be any database connection string like `sqlite:///path/to/my/file` or `postgres://user:pass@host:port/db`. + +### Options + +| Option | Description | +| ----------------------------------------- | -------------------------------------------------------------------------------------- | +| `-c, --command COMMAND` | run only single command (SQL or internal) and exit | +| `-f, --file FILE` | execute commands from file and exit | +| `-w, --no-password` | never prompt for password | +| `-X, --no-init` | do not execute initialization scripts (aliases: `--no-rc` `--no-psqlrc` `--no-usqlrc`) | +| `-o, --out FILE` | output file | +| `-W, --password` | force password prompt (should happen automatically) | +| `-1, --single-transaction` | execute as a single transaction (if non-interactive) | +| `-v, --set NAME=VALUE` | set variable NAME to VALUE (see \set command, aliases: --var --variable) | +| `-N, --cset NAME=DSN` | set named connection NAME to DSN (see \cset command) | +| `-P, --pset VAR=ARG` | set printing option VAR to ARG (see \pset command) | +| `-F, --field-separator FIELD-SEPARATOR` | field separator for unaligned and CSV output | +| `-R, --record-separator RECORD-SEPARATOR` | record separator for unaligned and CSV output (default \n) | +| `-T, --table-attr TABLE-ATTR` | set HTML table tag attributes (e.g., width, border) | +| `-A, --no-align` | unaligned table output mode | +| `-H, --html` | HTML table output mode | +| `-t, --tuples-only` | print rows only | +| `-x, --expanded` | turn on expanded table output | +| `-z, --field-separator-zero` | set field separator for unaligned and CSV output to zero byte | +| `-0, --record-separator-zero` | set record separator for unaligned and CSV output to zero byte | +| `-J, --json` | JSON output mode | +| `-C, --csv` | CSV output mode | +| `-G, --vertical` | vertical output mode | +| `-q, --quiet` | run quietly (no messages, only query output) | +| `--config string` | config file | + +## Commands + +| Command | Description | +| ---------------------------------- | ----------------------------------------------------------------------------- | +| **General:** | | +| `\q` | quit usql | +| `\quit` | alias for `\q` | +| `\drivers` | show database drivers available to usql | +| **Connection:** | | +| `\c DSN` | connect to database url | +| `\c DRIVER PARAMS...` | connect to database with driver and parameters | +| `\cset [NAME [DSN]]` | set named connection, or list all if no parameters | +| `\cset NAME DRIVER PARAMS...` | define named connection for database driver | +| `\Z` | close database connection | +| `\password [USERNAME]` | change the password for a user | +| `\conninfo` | display information about the current database connection | +| **Operating System:** | | +| `\cd [DIR]` | change the current working directory | +| `\getenv VARNAME ENVVAR` | fetch environment variable | +| `\setenv NAME [VALUE]` | set or unset environment variable | +| `\! [COMMAND]` | execute command in shell or start interactive shell | +| `\timing [on/off]` | toggle timing of commands | +| **Variables:** | | +| `\prompt [-TYPE] VAR [PROMPT]` | prompt user to set variable | +| `\set [NAME [VALUE]]` | set internal variable, or list all if no parameters | +| `\unset NAME` | unset (delete) internal variable | +| **Query Execute:** | | +| `\g [(OPTIONS)] [FILE] or ;` | execute query (and send results to file or pipe) | +| `\G [(OPTIONS)] [FILE]` | as \g, but forces vertical output mode | +| `\gx [(OPTIONS)] [FILE]` | as \g, but forces expanded output mode | +| `\gexec` | execute query and execute each value of the result | +| `\gset [PREFIX]` | execute query and store results in usql variables | +| **Query Buffer:** | | +| `\e [FILE] [LINE]` | edit the query buffer (or file) with external editor | +| `\p` | show the contents of the query buffer | +| `\raw` | show the raw (non-interpolated) contents of the query buffer | +| `\r` | reset (clear) the query buffer | +| **Input/Output:** | | +| `\copy SRC DST QUERY TABLE` | copy query from source url to table on destination url | +| `\copy SRC DST QUERY TABLE(A,...)` | copy query from source url to columns of table on destination url | +| `\echo [-n] [STRING]` | write string to standard output (-n for no newline) | +| `\qecho [-n] [STRING]` | write string to \o output stream (-n for no newline) | +| `\warn [-n] [STRING]` | write string to standard error (-n for no newline) | +| `\o [FILE]` | send all query results to file or pipe | +| **Informational:** | | +| `\d[S+] [NAME]` | list tables, views, and sequences or describe table, view, sequence, or index | +| `\da[S+] [PATTERN]` | list aggregates | +| `\df[S+] [PATTERN]` | list functions | +| `\di[S+] [PATTERN]` | list indexes | +| `\dm[S+] [PATTERN]` | list materialized views | +| `\dn[S+] [PATTERN]` | list schemas | +| `\dp[S] [PATTERN]` | list table, view, and sequence access privileges | +| `\ds[S+] [PATTERN]` | list sequences | +| `\dt[S+] [PATTERN]` | list tables | +| `\dv[S+] [PATTERN]` | list views | +| `\l[+]` | list databases | +| `\ss[+] [TABLE/QUERY] [k]` | show stats for a table or a query | +| **Formatting:** | | +| `\pset [NAME [VALUE]]` | Set table output option | +| `\a` | Toggle between unaligned and aligned output mode | +| `\C [STRING]` | Set table title, or unset if none | +| `\f [STRING]` | Show or set field separator for unaligned query output | +| `\H` | Toggle HTML output mode | +| `\T [STRING]` | Set HTML