joelsql - SQL Toolchain
joelsql is the command-line tool for working with SQL in JOEL. It provides a complete SQL development and execution environment.
Installation
joelsql is included with JOEL:
joelsql --versionInteractive SQL Shell
Start an interactive SQL REPL:
joelsqlExample session:
$ joelsql
JOEL SQL v0.1.0
Type 'help' for help, 'exit' to quit.
> SELECT * FROM users LIMIT 5;
┌────┬──────────┬─────┐
│ id │ name │ age │
├────┼──────────┼─────┤
│ 1 │ Alice │ 25 │
│ 2 │ Bob │ 30 │
│ 3 │ Charlie │ 35 │
│ 4 │ Diana │ 28 │
│ 5 │ Eve │ 32 │
└────┴──────────┴─────┘
> exitExecute SQL Files
Run SQL queries from files:
# Execute single file
joelsql run query.joel
# Execute with parameters
joelsql run analytics.joel --param min_age=25 --param city="NYC"
# Execute multiple files
joelsql run *.joel
# Execute with output
joelsql run query.joel --output results.jsonQuery Execution
Execute SQL queries directly from command line:
# Simple query
joelsql query "SELECT * FROM users WHERE age > 30"
# Query CSV file
joelsql query "SELECT * FROM 'data.csv' WHERE age > 30"
# Query with formatted output
joelsql query "SELECT * FROM employees" --format table
# Export results
joelsql query "SELECT * FROM sales" --output sales.csv
joelsql query "SELECT * FROM sales" --output sales.json
joelsql query "SELECT * FROM sales" --output sales.parquet
# Show query timing
joelsql query "SELECT * FROM large_table" --timingDatabase Management
Manage databases and tables:
# List databases
joelsql databases
# List tables
joelsql tables
# Describe table schema
joelsql describe users
# Show table data
joelsql show users --limit 10
# Create database
joelsql create-db analytics
# Drop database
joelsql drop-db old_dbDatabase Connections
Connect to external databases:
# Connect to PostgreSQL
joelsql connect postgresql://localhost/mydb
# Add named connection
joelsql connection add prod postgresql://prod-server/db
# List connections
joelsql connection list
# Test connection
joelsql connection test prod
# Use specific connection
joelsql query "SELECT * FROM users" --connection prod
# Remove connection
joelsql connection remove prodQuery Analysis
Analyze and optimize queries:
# Show query execution plan
joelsql explain "SELECT * FROM employees WHERE age > 30"
# Analyze query performance
joelsql analyze "SELECT * FROM large_table WHERE id = 1"
# Suggest indexes
joelsql suggest-indexes query.joel
# Optimize query
joelsql optimize query.joel --output optimized.joelSQL Scripts
Execute SQL scripts with variables:
# Execute script with variables
joelsql script report.joel --vars year=2024 quarter=Q1
# Execute with environment variables
joelsql script query.joel --env
# Batch execution
joelsql batch queries.joelData Import/Export
Bulk data operations:
# Import CSV to table
joelsql import users.csv --table users
# Export table to CSV
joelsql export users --output users.csv
# Import from JSON
joelsql import data.json --table products
# Export to Parquet
joelsql export sales --output sales.parquet --format parquet
# Import with schema
joelsql import data.csv --table users --schema schema.jsonDatabase Migrations
Manage schema changes:
# Create migration
joelsql migration create add_users_table
# Run migrations
joelsql migration up
# Rollback migration
joelsql migration down
# Show migration status
joelsql migration status
# Create migration from SQL file
joelsql migration create-from-file schema.joelSQL Linting and Formatting
Code quality tools:
# Lint SQL file
joelsql lint query.joel
# Format SQL file
joelsql format query.joel
# Check SQL syntax
joelsql check query.joel
# Auto-fix common issues
joelsql fix query.joelConfiguration
Configure joelsql behavior:
# Show configuration
joelsql config show
# Set default connection
joelsql config set default_connection prod
# Set output format
joelsql config set output_format json
# Set query timeout
joelsql config set query_timeout 30Examples
Query CSV File
joelsql query "SELECT name, age FROM 'users.csv' WHERE age > 25"Export Query Results
joelsql query "SELECT * FROM sales WHERE date > '2024-01-01'" \
--output sales_2024.csv \
--format csvExecute SQL Script
# report.joel
sql result =
SELECT
DATE(created_at) as date,
COUNT(*) as count,
SUM(amount) as total
FROM sales
WHERE created_at > '2024-01-01'
GROUP BY DATE(created_at)
ORDER BY date
# Execute
joelsql run report.joel --output report.jsonDatabase Migration
# Create migration
joelsql migration create add_indexes
# Edit migration file (migrations/001_add_indexes.joel)
sql CREATE INDEX idx_users_email ON users(email)
sql CREATE INDEX idx_users_age ON users(age)
# Run migration
joelsql migration upCommand Reference
Core Commands
joelsql- Start interactive shelljoelsql run <file>- Execute SQL filejoelsql query <sql>- Execute SQL queryjoelsql explain <sql>- Show query plan
Database Commands
joelsql databases- List databasesjoelsql tables- List tablesjoelsql describe <table>- Show table schemajoelsql show <table>- Show table datajoelsql create-db <name>- Create databasejoelsql drop-db <name>- Drop database
Connection Commands
joelsql connect <url>- Connect to databasejoelsql connection add <name> <url>- Add connectionjoelsql connection list- List connectionsjoelsql connection test <name>- Test connectionjoelsql connection remove <name>- Remove connection
Data Commands
joelsql import <file> --table <table>- Import datajoelsql export <table> --output <file>- Export data
Migration Commands
joelsql migration create <name>- Create migrationjoelsql migration up- Run migrationsjoelsql migration down- Rollback migrationjoelsql migration status- Show status
Utility Commands
joelsql lint <file>- Lint SQLjoelsql format <file>- Format SQLjoelsql check <file>- Check syntaxjoelsql analyze <sql>- Analyze queryjoelsql optimize <file>- Optimize query