Batch Processing

Overview

sqry batch executes a file of queries in a single invocation, sharing the loaded index across all queries. This avoids the per-query startup cost and is useful for CI pipelines, automated reports, and large-scale analysis.


Usage

Create a query file with one query per line:

# queries.txt
kind:function AND async:true
callers:authenticate
kind:class AND path:src/models/**

Blank lines and lines starting with # are ignored. Each non-comment line must be a structural query expression accepted by sqry query.

Run all queries:

sqry batch --queries queries.txt .

The --queries <FILE> flag is required; PATH is positional and defaults to the current directory.


Options

FlagDefaultDescription
--queries <FILE>(required)File containing one query per line
--output <FORMAT>textOutput format: text, json, jsonl, or csv
--output-file <FILE>stdoutWrite results to a file instead of stdout
--continue-on-errorfalseKeep running if a query fails
--statsfalsePrint aggregate statistics after completion
--sequentialfalseRun queries one at a time instead of in parallel (debugging)

Parallel execution

By default, sqry batch runs queries in parallel, using the loaded index concurrently. Progress is written to stderr. The rendered output preserves the query positions from the input file.

Use --sequential when you need deterministic output ordering or when debugging a specific query:

sqry batch --queries queries.txt . --sequential --stats

Structured output

JSON batch output contains a session object, a queries array for successful queries, and an errors array when --continue-on-error is used:

sqry batch --queries queries.txt . --output json

For one JSON object per line, use --output jsonl. Use --output csv for a comma-separated summary per query.

{
  "session": {
    "path": ".",
    "executor_setup_ms": 42,
    "total_queries": 2,
    "success_count": 2,
    "failure_count": 0,
    "total_query_time_ms": 18,
    "average_query_time_ms": 9
  },
  "queries": [
    {
      "position": 1,
      "query": "kind:function AND async:true",
      "elapsed_ms": 12,
      "result_count": 4,
      "displayed_count": 4,
      "results": []
    }
  ]
}

Result arrays are included for JSON and JSONL unless you run with the global --count flag. Text and CSV output summarize each query. CSV columns are position,query,elapsed_ms,result_count,displayed_count,error. JSONL emits one JSON object per query, one per line — ideal for streaming consumers.


Error handling

Without --continue-on-error, the batch stops at the first failed query and exits with a non-zero code. With it, failed queries are reported in the output but execution continues:

sqry batch --queries queries.txt . --continue-on-error --stats

The --stats flag prints a summary at the end showing which queries succeeded, failed, and how long each took.


CI example

Run a standard set of quality checks in a single step:

- name: Run sqry quality checks
  run: |
    cat > /tmp/checks.txt << 'EOF'
    callers:authenticate
    kind:function AND name~=/TODO/
    EOF
    sqry batch --queries /tmp/checks.txt . --output json --continue-on-error