Nik Clayton c81bb0238e
refactor: Reformat SQL queries for ease of reading (#1237)
The database queries in the @Query annotations were in a range of
different styles which made them difficult to read, and difficult to
write new ones in a consistent style.

Fix this.

Write a new tool, `sqlfmt`. This processes the DAO files looking for
`@Query(...)` annotations. It extracts the SQL from those annotations
and calls `sqlfluff` (https://github.com/sqlfluff/sqlfluff, which must
be installed separately) to lint and fix formatting issues in the SQL.

The file is re-written with the newly formatted SQL queries.
2025-01-26 19:11:19 +01:00
..

fmtsql

Synopsis

fmtsql formats the SQL in @Query annotations using sqlfluff, which must be installed on your system.

Usage

From the parent directory, run:

./runtools fmtsql

The result may not be 100% ktlint compatible, so then run:

./gradlew ktlintformat

Verify the modifications made to the DAO files, and commit the result.

Options

  • --dir: Path to the DAO files containing @Query annotations. The default is the path to Pachli DAO files
  • --sqlfluff: Full path to the sqlfluff executable

Configuration

SQL formatting is controlled by the .sqlfluff configuration file in the project's root directory.