A quick reference for all ETL command-line operations.
go install github.com/titpetric/etl/cmd/etl@mainVerify installation:
etl --helpSet environment variables to connect to your database:
export ETL_DB_DSN="sqlite://file:database.db"export ETL_DB_DSN="postgres://user:password@localhost:5432/dbname"export ETL_DB_DSN="mysql://user:password@tcp(localhost:3306)/dbname"# Set up the database
export ETL_DB_DSN="sqlite://file:myapp.db"
# Initialize schema from SQL file
etl query schema.sqlCREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS orders (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id),
total_amount DECIMAL(10, 2),
status TEXT DEFAULT 'pending',
order_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);# Get one user by email
etl get users email=alice@example.com
# Get one order by ID
etl get orders id=1# Get all users
etl get users --all
# Get all orders
etl get orders --all# Query from file with parameter substitution
etl query queries/users-by-name.sql name="Alice"
# Multiple parameters
etl query queries/orders-by-user.sql user_id=1 status=pendingSELECT id, name, email, created_at
FROM users
WHERE name LIKE '%' || :name || '%'
ORDER BY created_at DESC;# Insert a single record with arguments
etl insert users name="Bob Smith" email="bob@example.com"
# Insert from JSON
echo '{"name":"Carol White","email":"carol@example.com"}' | etl insert users
# Insert from file with overrides
cat user.json | etl insert users status=active# Update by primary key
echo '{"name":"Alice Updated"}' | etl update users id=1
# Update with conditions
etl update users status=active created_at="2025-01-01"
# Bulk update from JSON
cat updates.json | etl update users id=:idSince the CLI doesn't provide direct delete functionality, create a query file:
DELETE FROM users WHERE id = :id
RETURNING id, name, email;Then execute:
etl query queries/delete-user.sql id=3Use the @file syntax to read JSON from files:
# Store file contents as JSON column
etl insert documents file_data=@data.jsonCombine with jq for data transformation:
# Transform and insert
cat api-response.json | jq '.users[]' | etl insert users
# Filter and update
cat records.json | jq 'select(.status=="pending")' | etl update orders id=:idStart the API/Web server:
etl serverBy default listens on the address configured in etl.yml (typically :8080).
See docs/server.md for server configuration and API development.
# 1. Initialize database
export ETL_DB_DSN="sqlite://file:app.db"
etl query schema.sql
# 2. Insert users
echo '{"name":"Alice Johnson","email":"alice@example.com"}' | etl insert users
echo '{"name":"Bob Smith","email":"bob@example.com"}' | etl insert users
# 3. Get all users
etl get users --all
# 4. Update a user
echo '{"email":"alice.updated@example.com"}' | etl update users id=1
# 5. Get updated user
etl get users id=1
# 6. Start server for API access
etl server- Use pipes to process multiple records at once for bulk operations
- Values support dynamic data via shell expansion:
etl insert users created_at=$(date -I) - Keep
.sqlfiles database-specific to handle syntax differences - Pipe through
jqfirst to validate JSON before database operations - Use
--dryflag if available to preview operations without committing
- Connection errors: Check
ETL_DB_DSNenvironment variable - Missing table: Run schema initialization with
etl query schema.sql - JSON parse errors: Validate JSON with
jqbefore piping to etl - SQL syntax errors: Test queries directly in database client first, then move to .sql files