The surqlfmt tool reformats .surql files to follow a consistent style. It adjusts whitespace, indentation, and keyword casing so that SurrealQL code is easy to read and review.
surqlfmt is a third command-line tool alongside surreal and surrealctl. It is shipped as an npm package rather than as part of the surreal binary, it never connects to a database, and it only reads and writes files.
Installation
The tool can be installed through a single npm install command:
npm install -g @surrealdb/surql-fmtUsage
surqlfmt [OPTIONS] [FILES]...The tool prints the reformatted file by default, and reformats a .surql file in place when --write is passed.
# Format a single file
surqlfmt ./query.surql
# Check if files are formatted
surqlfmt --check ./src/**/*.surql
# Format from stdin
cat query.surql | surqlfmt --stdin
# Configure indentation and line length
surqlfmt --indent 4 --indent-char tab --max-line-length 120 *.surql
# Write files in-place
surqlfmt --write ./src/**/*.surqlFor the options of the version you have installed, run surqlfmt --help.
When to use the formatter
Before committing - run
surqlfmton any.surqlmigration or seed files to keep diffs clean.In CI - add a
surqlfmt --checkstep to catch inconsistencies early.During development - pipe ad-hoc queries through the formatter for readability.
For the other command-line tools, see the CLI tools overview.