Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/iterate/sqlfu/llms.txt

Use this file to discover all available pages before exploring further.

sqlfu includes a SQL formatter that started from a vendored copy of sql-formatter and then diverged. The current defaults are intentionally opinionated: lowercase keywords, SQLite-first dialect, and a bias toward keeping simple clause bodies inline when they still read well. You can run it from the CLI to rewrite files, wire it into ESLint for editor and CI feedback, or call it programmatically from TypeScript.

CLI

Rewrite .sql files in place by passing file paths, directories, or glob patterns:
npx sqlfu format "sql/**/*.sql" definitions.sql
The command reports which files changed and which were already correct:
Formatted files:
  sql/get-posts.sql
Already formatted:
  definitions.sql

ESLint

The lint plugin exposes the same formatter through the sqlfu/format-sql rule. Wire it up in your ESLint flat config:
eslint.config.js
import sqlfu from 'sqlfu/lint-plugin';

export default [
  {
    files: ['**/*.sql'],
    plugins: {sqlfu},
    processor: 'sqlfu/sql',
    rules: {
      'sqlfu/format-sql': 'error',
    },
  },
];
Then run ESLint with autofix to rewrite files:
eslint --fix "sql/**/*.sql"
The same rule also flags inline SQL template literals in TypeScript and JavaScript files that do not match the formatter’s output. Use this when you want formatting enforced in the same editor and CI loop as the rest of your lint rules. See Lint plugin for the full rule set, including sqlfu/query-naming and sqlfu/generated-query-freshness.

Programmatic

Import format from sqlfu/api to format a SQL string in TypeScript:
import {format} from 'sqlfu/api';

const formatted = format('SELECT Id, Slug FROM Posts WHERE Published = 1');
// → 'select id, slug from posts where published = 1'

Opinionated defaults

The formatter makes three deliberate choices:
  • Lowercase — SQL keywords are downcased. SELECT becomes select, WHERE becomes where.
  • SQLite-first — dialect defaults are tuned for SQLite syntax, not ANSI SQL or PostgreSQL.
  • Inline when readable — simple clause bodies stay on one line rather than being broken across multiple lines. select id, slug from posts where id = 1 is left inline; longer or more complex queries are formatted with line breaks.
These choices are not configurable. The formatter is intentionally opinionated so that a project has one canonical SQL style rather than a style that varies by author preference.

Build docs developers (and LLMs) love