Add jrq query wrapper script and deploy integration

Adds jrq, a convenience wrapper that loads connection details from
~/.jrqrc so users can run query mode without typing credentials each
time. deploy.sh now installs jrq alongside jrunner in all deploy modes,
with a /usr/local/bin symlink for global installs. jrq resolves the
jrunner binary relative to its own location to avoid hardcoded paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Paul Trowbridge 2026-02-26 06:40:44 -05:00
parent c0f6e3a6e6
commit 6a925b83ca
3 changed files with 122 additions and 1 deletions

View File

@ -51,9 +51,13 @@ echo "Building jrunner..."
if [ "$DEPLOY_MODE" = "local" ]; then
echo "Installing locally with gradle..."
./gradlew installDist
echo "Installing jrq wrapper script..."
cp jrq "${DEPLOY_DIR}/bin/jrq"
chmod +x "${DEPLOY_DIR}/bin/jrq"
echo ""
echo "✅ Installed locally at: ${DEPLOY_DIR}"
echo "Run './jrunner/build/install/jrunner/bin/jrunner --help' to test"
echo "Run './jrunner/build/install/jrunner/bin/jrq' for query wrapper usage"
else
# Global or custom deployment
if [ ! -d "${DEPLOY_DIR}" ]; then
@ -73,17 +77,25 @@ else
echo "Fixing ownership..."
sudo chown -R $USER:$USER "${DEPLOY_DIR}"
# Copy jrq wrapper script
echo "Installing jrq wrapper script..."
sudo cp jrq "${DEPLOY_DIR}/bin/jrq"
sudo chmod +x "${DEPLOY_DIR}/bin/jrq"
# Create symlink for global install
if [ "$DEPLOY_MODE" = "global" ]; then
echo "Creating symlink at /usr/local/bin/jrunner..."
echo "Creating symlinks at /usr/local/bin/..."
sudo ln -sf /opt/jrunner/bin/jrunner /usr/local/bin/jrunner
sudo ln -sf /opt/jrunner/bin/jrq /usr/local/bin/jrq
fi
echo ""
echo "✅ Deployed to ${DEPLOY_DIR}"
echo "Run '${DEPLOY_DIR}/bin/jrunner --help' to test"
echo "Run '${DEPLOY_DIR}/bin/jrq' for query wrapper usage"
if [ "$DEPLOY_MODE" = "global" ]; then
echo "Or simply: jrunner --help"
echo " jrq (for query wrapper)"
fi
fi

66
jrq Executable file
View File

@ -0,0 +1,66 @@
#!/bin/bash
# jrq - jrunner query wrapper for piping to visidata
# Usage: jrq <sql_file> [format]
# Example: jrq query.sql
# jrq query.sql tsv
set -e
# Configuration
# Override these with environment variables or create ~/.jrqrc
CONFIG_FILE="${HOME}/.jrqrc"
# Default values
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
JR_BIN="${JR_BIN:-${SCRIPT_DIR}/jrunner}"
JR_URL="${JR_URL:-}"
JR_USER="${JR_USER:-}"
JR_PASS="${JR_PASS:-}"
JR_FORMAT="${JR_FORMAT:-csv}"
# Load config file if it exists
if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
fi
# Parse arguments
if [ $# -lt 1 ]; then
echo "Usage: jrq <sql_file> [format]"
echo ""
echo "Configuration (via environment variables or ~/.jrqrc):"
echo " JR_URL - JDBC connection URL (required)"
echo " JR_USER - Database username (required)"
echo " JR_PASS - Database password (required)"
echo " JR_BIN - Path to jrunner binary (default: /opt/jrunner/jrunner/build/install/jrunner/bin/jrunner)"
echo " JR_FORMAT - Output format: csv or tsv (default: csv)"
echo ""
echo "Example ~/.jrqrc:"
echo " JR_URL=\"jdbc:as400://s7830956\""
echo " JR_USER=\"username\""
echo " JR_PASS=\"password\""
echo ""
echo "Example usage:"
echo " jrq query.sql # outputs CSV to stdout"
echo " jrq query.sql | vd # pipe to visidata"
echo " jrq query.sql tsv # output TSV format"
exit 1
fi
SQL_FILE="$1"
FORMAT="${2:-$JR_FORMAT}"
# Validate configuration
if [ -z "$JR_URL" ] || [ -z "$JR_USER" ] || [ -z "$JR_PASS" ]; then
echo "Error: Missing database connection configuration" >&2
echo "Set JR_URL, JR_USER, and JR_PASS environment variables or create ~/.jrqrc" >&2
exit 1
fi
# Validate SQL file exists
if [ ! -f "$SQL_FILE" ]; then
echo "Error: SQL file not found: $SQL_FILE" >&2
exit 1
fi
# Execute jrunner
"$JR_BIN" -scu "$JR_URL" -scn "$JR_USER" -scp "$JR_PASS" -sq "$SQL_FILE" -f "$FORMAT"

View File

@ -113,6 +113,49 @@ jrunner -scu "jdbc:sqlserver://hostname:1433;databaseName=mydb" -scn user -scp p
jrunner -scu "jdbc:postgresql://hostname:5432/dbname" -scn user -scp pass -sq query.sql
```
### jrq - Query Mode Wrapper
The `jrq` wrapper script simplifies query mode usage by storing connection details in a config file, eliminating the need to type credentials repeatedly.
**Setup:**
Create `~/.jrqrc` with your database connection details:
```bash
JR_URL="jdbc:as400://s7830956"
JR_USER="myusername"
JR_PASS="mypassword"
```
**Usage:**
```bash
# Output to stdout
jrq query.sql
# Pipe to visidata
jrq query.sql | vd
# Use TSV format
jrq query.sql tsv
# Pipe TSV to less with column display
jrq query.sql tsv | less -S
```
**Configuration options in ~/.jrqrc:**
- `JR_URL` - JDBC connection URL (required)
- `JR_USER` - Database username (required)
- `JR_PASS` - Database password (required)
- `JR_BIN` - Path to jrunner binary (default: /opt/jrunner/jrunner/build/install/jrunner/bin/jrunner)
- `JR_FORMAT` - Default output format: csv or tsv (default: csv)
**Note:** You can also set these as environment variables instead of using a config file:
```bash
export JR_URL="jdbc:as400://hostname"
export JR_USER="username"
export JR_PASS="password"
jrq query.sql | vd
```
### Migration Mode
Full migration mode with both source and destination: