Tool to query any RDBMS with JSON output
Add jq::expr argument support
Relicense under Apache 2.0 license
Additional refactoring for use in chisel



You can also use your local clone with git send-email.


sql(1) is a small Go tool to query relational databases with JSON output. It supports passing arguments with placeholders, parameter expansion as in column IN (?) via sqlx, and execution of multiple statements. It's intended for use along with tools like jq and miller.


To build the sql binary, you need Go 1.16 or later installed. You can then use go build as usual to build, or bmake bin/sql. Currently, there is no difference between the two.

To build the man page, you need [scdoc] installed. You can then use bmake sql.1 to build the man pages.

Currently, MySQL and Postgres support is built in by default, but can be omitted by setting the build tags omit_mysql or omit_postgres, as desired. This shouldn't have much relevance to users, but may be more important in the future if drivers that require C are added. You can pass these tags to the bmake by setting the GO_TAGS variable to one or more space or comma-separated tags. For example: bmake GO_TAGS=omit_mysql.


Pre-built binaries are not available for sql(1) right now, so you'll need to build and install it yourself:

$ git clone https://git.sr.ht/~nilium/sql
$ cd sql

# Optional: check out a version.
$ git checkout v0.1.0

# Build the program:
$ bmake all
$ bin/sql -h
Usage: sql [OPTIONS] <DSN> {QUERY [ARGS...]...}

# Optional: install to a PREFIX.
$ sudo bmake install

When running bmake install, you can optionally set the PREFIX variable to change the install location. This defaults to /usr/local. you can also set either MAN_PREFIX (default: $PREFIX/share/man) or BIN_PREFIX (default: $PREFIX/bin) to set the path that man pages and binaries are installed to, respectively.


Currently, only the included scdoc man page under sql.1.scd provides usage information. If you have scdoc, this can be compiled to a man page to view it in man(1). See the Building section above.


The sql tool is licensed under the GNU GPL v3.0. A copy of the license is provided in the COPYING text in this source tree, but may also be read at https://www.gnu.org/licenses/.