Skip to content

Commit

Permalink
refactor: Reformat SQL queries for ease of reading (#1237)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikclayton authored Jan 26, 2025
1 parent 353f123 commit c81bb02
Show file tree
Hide file tree
Showing 20 changed files with 1,290 additions and 545 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ indent_size = 2

# Disable ktlint on generated source code, see
# https://github.com/JLLeitschuh/ktlint-gradle/issues/746
[**/build/generated/source/**]
[**/build/generated/**]
ktlint = disabled
32 changes: 32 additions & 0 deletions .sqlfluff
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[sqlfluff]
dialect = sqlite
templater = placeholder
max_line_length = 120

# Disable specific rules:
# - CP02 so identifier case is left alone.
# - AM04, "Query produces an unknown number of result columns", allow "SELECT *"
# - ST10, bug with placeholders in 3.3.0, https://github.com/sqlfluff/sqlfluff/issues/6493
exclude_rules = CP02,AM04,ST10

[sqlfluff:templater:placeholder]
param_style = colon

# Force a line break before FROM.
[sqlfluff:layout:type:from_clause]
keyword_line_position = leading

# Force `SET` to a separate line.
[sqlfluff:layout:type:set_clause_list]
keyword_line_position = alone

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper
[sqlfluff:rules:capitalisation.identifiers]
#extended_capitalisation_policy = camel
[sqlfluff:rules:capitalisation.functions]
extended_capitalisation_policy = upper
[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = upper
[sqlfluff:rules:capitalisation.types]
extended_capitalisation_policy = upper
Loading

0 comments on commit c81bb02

Please sign in to comment.