89.4. usql-0.21.6
Command-line SQL client for PostgreSQL, SQLite and other databases
| Version | 0.21.6, release 1 |
| Shelf | database — Database engines, embedded key-value stores, database servers, clients and full-text indexes |
| Phase | 41_system (System), 336 of 1047 in build order |
| Licence | MIT |
| Homepage | https://github.com/xo/usql |
| Build time | 1.0 SBU |
| Installed size | 22.0 MiB in 2 files |
| Recipe | ports/core/database/usql/kpkgbuild |
About
usql is a universal command-line SQL client modelled on PostgreSQL’s psql: the same backslash commands, variables and completion, against many kinds of database through Go’s database/sql drivers, with connections named as URLs (pg://, sq:file.db, my://, dk:file.duckdb). It can copy query results between databases with \copy.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/database.txt:
Fifty drivers for two engines that are actually here is the default build; this one is
no_baseplus postgres, sqlite3 and mysql.
Sources
usql-0.21.6.tar.gz(324.4 KiB)
sha2562997ae39ff509694aa7ce8e60dcf6b2ff2c431e0908332a7c28e95db64521c15
upstream: https://github.com/xo/usql/archive/refs/tags/v0.21.6.tar.gz
archive copy: sources-1/database--usql-0.21.6.tar.gzusql-vendor-0.21.6.tar.xz(168.9 MiB)
sha256bf9f0c39971855f915f0fb310352221d121cf8afacbbb3f7014e948f36f2f11f
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-1/database--usql-vendor-0.21.6.tar.xz
Dependencies
Depends on: go, sqlite, duckdb.
Required by: no port names it.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install usql'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/database/usql.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/database/usql
echo '2997ae39ff509694aa7ce8e60dcf6b2ff2c431e0908332a7c28e95db64521c15 usql-0.21.6.tar.gz' | sha256sum -c -
echo 'bf9f0c39971855f915f0fb310352221d121cf8afacbbb3f7014e948f36f2f11f usql-vendor-0.21.6.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/usql
SRC=$SRC_ROOT/usql-0.21.6
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf usql-0.21.6.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz
export CGO_ENABLED=1
go build -mod=vendor \
-tags "no_base postgres sqlite3 libsqlite3 mysql csvq duckdb duckdb_use_lib" \
-ldflags "-s -w" -o usql
install -Dm755 usql $PKG/usr/bin/usql
The switches, and why each is set:
CGO_ENABLED=1— Build with cgo, which the SQLite and DuckDB drivers need: both bind a C library.-tags "no_base postgres sqlite3 libsqlite3 mysql csvq duckdb duckdb_use_lib"— Choose the drivers.no_basedrops upstream’s base set (PostgreSQL, MySQL, SQLite, Microsoft SQL Server, Oracle, ClickHouse and CSVQ); the tags after it add back PostgreSQL, SQLite, MySQL and CSVQ (CSV, TSV and JSON files queried as tables), and add DuckDB, which is not in the base set.libsqlite3makesgo-sqlite3link the system sqlite instead of compiling the SQLite amalgamation it carries, andduckdb_use_libmakes DuckDB’s Go bindings link the systemlibduckdbfrom duckdb instead of the prebuilt static archives the bindings carry inlib/linux-amd64.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/usql, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf usql-0.21.6-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/usql, and runs the triggers its paths call for.
Contents
Installed programs: usql.
Installed directories: /usr/share/licenses/usql.
Notes
usql is built from a vendor bundle, usql-vendor-<version>.tar.xz, made by ports/fetch with go mod vendor; see Vendoring. The installed binary NEEDs libsqlite3.so.0 and libduckdb.so.