sqlalign 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqlalign/__init__.py +10 -0
- sqlalign/align.py +145 -0
- sqlalign/bodylint.py +125 -0
- sqlalign/casing.py +182 -0
- sqlalign/cli.py +360 -0
- sqlalign/commas.py +58 -0
- sqlalign/config.py +28 -0
- sqlalign/configfile.py +194 -0
- sqlalign/formatter.py +609 -0
- sqlalign/gui.py +721 -0
- sqlalign/ir.py +38 -0
- sqlalign/keywordcase.py +127 -0
- sqlalign/layout/__init__.py +312 -0
- sqlalign/layout/case.py +222 -0
- sqlalign/layout/comments.py +530 -0
- sqlalign/layout/conditions.py +344 -0
- sqlalign/layout/cte.py +81 -0
- sqlalign/layout/ddl.py +424 -0
- sqlalign/layout/dml.py +287 -0
- sqlalign/layout/expr.py +119 -0
- sqlalign/layout/fromjoin.py +310 -0
- sqlalign/layout/grouporder.py +135 -0
- sqlalign/layout/select.py +523 -0
- sqlalign/layout/setop.py +78 -0
- sqlalign/layout/subquery.py +245 -0
- sqlalign/layout/window.py +207 -0
- sqlalign/lint.py +173 -0
- sqlalign/plpgsql.py +437 -0
- sqlalign/splitter.py +241 -0
- sqlalign/sqlfluffconfig.py +88 -0
- sqlalign/style.py +215 -0
- sqlalign/templating.py +87 -0
- sqlalign-1.0.1.dist-info/METADATA +404 -0
- sqlalign-1.0.1.dist-info/RECORD +37 -0
- sqlalign-1.0.1.dist-info/WHEEL +4 -0
- sqlalign-1.0.1.dist-info/entry_points.txt +2 -0
- sqlalign-1.0.1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sqlalign
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: A SQL formatter that cannot change what your SQL means
|
|
5
|
+
Project-URL: Homepage, https://sqlalign.lumaru.app/
|
|
6
|
+
Project-URL: Documentation, https://sqlalign.lumaru.app/v1/
|
|
7
|
+
Project-URL: Source, https://github.com/pua2/sqlalign
|
|
8
|
+
Project-URL: Issues, https://github.com/pua2/sqlalign/issues
|
|
9
|
+
Author: Pavan Amin
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: dbt,formatter,plpgsql,postgres,redshift,sql,tsql
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: SQL
|
|
20
|
+
Classifier: Topic :: Database
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Classifier: Topic :: Text Processing :: Filters
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.12
|
|
25
|
+
Requires-Dist: sqlglot<30.15,>=30.14
|
|
26
|
+
Provides-Extra: lint
|
|
27
|
+
Requires-Dist: sqlfluff<5,>=4.2; extra == 'lint'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# sqlalign
|
|
31
|
+
|
|
32
|
+
A SQL formatter for **Postgres**, **Redshift** and **SQL Server** that **cannot change what your
|
|
33
|
+
SQL means**. Every statement it formats is re-parsed and AST-compared against the
|
|
34
|
+
input; if the output would differ semantically — or if the engine doesn't fully
|
|
35
|
+
model the construct — the statement is passed through **byte-identical** with a
|
|
36
|
+
warning instead. It reformats presentation and nothing else: identifiers, string
|
|
37
|
+
literals, cast form (`::` vs `CAST`), `GROUP BY` references, and alias choices all
|
|
38
|
+
survive exactly as written.
|
|
39
|
+
|
|
40
|
+
Its layout is **columnar alignment**: operators, aliases, `AS` clauses, and
|
|
41
|
+
`ON`/`AND` conditions are padded into vertical columns by a fixpoint resolver —
|
|
42
|
+
alignment is the layout engine itself, not a post-pass over already-printed text.
|
|
43
|
+
It applies that same engine *inside* dollar-quoted (`$$`) plpgsql procedure and
|
|
44
|
+
function bodies.
|
|
45
|
+
|
|
46
|
+
```sql
|
|
47
|
+
FROM customers cust
|
|
48
|
+
INNER JOIN orders ord ON ord.customer_id = cust.customer_id
|
|
49
|
+
LEFT JOIN order_line_items line_items ON line_items.order_id = ord.order_id
|
|
50
|
+
LEFT JOIN shipping_addresses addr ON addr.order_id = ord.order_id
|
|
51
|
+
AND addr.address_type = 'shipping'
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## How it compares
|
|
55
|
+
|
|
56
|
+
Alignment is not unique to sqlalign, and this README won't pretend otherwise:
|
|
57
|
+
**sqlfluff** aligns column aliases (`layout:type:alias_expression` with
|
|
58
|
+
`spacing_before = align`), SSMS ships alignment options, and DataGrip aligns a
|
|
59
|
+
good deal including inside `$$` bodies. **pgFormatter**, **DataGrip**, and
|
|
60
|
+
**prettier-plugin-sql-cst** all format `$$` bodies too.
|
|
61
|
+
|
|
62
|
+
What is actually distinctive here:
|
|
63
|
+
|
|
64
|
+
- **The `ON`/`AND` condition column.** Aligning every JOIN's `ON` and `AND`
|
|
65
|
+
conditions into one column spanning the whole `FROM` block (see above) is not
|
|
66
|
+
something the surveyed tools do — their analogues break the line instead of
|
|
67
|
+
padding it.
|
|
68
|
+
- **Alignment as the engine, not a bolt-on.** sqlalign lays out lines first and
|
|
69
|
+
resolves every alignment column in a second fixpoint pass, so alignment
|
|
70
|
+
composes with wrapping instead of fighting it. For contrast, sql-formatter
|
|
71
|
+
removed its `tabulateAlias` and `commaPosition` options in v14 — both were
|
|
72
|
+
post-hoc rewrites over already-printed text.
|
|
73
|
+
- **The semantic guarantee above.** Formatters that also apply lint fixes can
|
|
74
|
+
rewrite your SQL — running `sqlfluff fix` on a query will happily turn `JOIN`
|
|
75
|
+
into `INNER JOIN`, insert `AS`, and reorder your `ON` operands. sqlalign
|
|
76
|
+
structurally cannot: a changed AST means the statement is passed through
|
|
77
|
+
untouched.
|
|
78
|
+
|
|
79
|
+
sqlalign deliberately does **not** lint. It won't unify your cast styles, force
|
|
80
|
+
aliases, or make `GROUP BY` references consistent — that's sqlfluff's job, and
|
|
81
|
+
the two are designed to run together.
|
|
82
|
+
|
|
83
|
+
**Want only some of the alignment?** `--align-targets` picks which columns are
|
|
84
|
+
padded; anything left out collapses to a single space. `--no-align` is the
|
|
85
|
+
shorthand for none of them.
|
|
86
|
+
|
|
87
|
+
| Target | Aligns |
|
|
88
|
+
|---|---|
|
|
89
|
+
| `aliases` | both of the next two |
|
|
90
|
+
| `column_aliases` | `AS x` in a select list |
|
|
91
|
+
| `table_aliases` | the alias in `FROM orders o` |
|
|
92
|
+
| `table_names` | the table after each `FROM`/`JOIN`, padding the keyword out to a shared column — **opt-in**, not part of the house style |
|
|
93
|
+
| `operators` | `=`, `!=`, `<`, `LIKE`, `IS` … in `WHERE`/`ON`/`HAVING`/`CASE` |
|
|
94
|
+
| `join_conditions` | the `ON`/`AND` column across a whole `FROM` block |
|
|
95
|
+
| `case_results` | `THEN` in a short-form `CASE` |
|
|
96
|
+
| `column_types` | column types in `CREATE TABLE` |
|
|
97
|
+
| `column_constraints` | `NOT NULL`/`DEFAULT`, and Redshift `ENCODE` |
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
sqlalign --align-targets aliases,operators query.sql
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`table_names` is the one target the default set leaves out, because it changes
|
|
104
|
+
the shape of the `FROM` block rather than refining it:
|
|
105
|
+
|
|
106
|
+
```sql
|
|
107
|
+
-- house -- with table_names
|
|
108
|
+
FROM customers cust FROM customers cust
|
|
109
|
+
LEFT JOIN orders ord LEFT JOIN orders ord
|
|
110
|
+
INNER JOIN payments pay INNER JOIN payments pay
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
sqlalign --align-targets aliases,table_names,operators,join_conditions query.sql
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Prefer trailing commas?** `--comma-position trailing` moves every separator
|
|
118
|
+
comma to the end of the preceding line (including onto the last line of a
|
|
119
|
+
multi-line item, and onto a CTE's closing paren):
|
|
120
|
+
|
|
121
|
+
```sql
|
|
122
|
+
SELECT cust.customer_id,
|
|
123
|
+
cust.email,
|
|
124
|
+
ord.total
|
|
125
|
+
FROM customers cust
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**Don't want the alignment?** `--no-align` keeps sqlalign's line structure and
|
|
129
|
+
drops the padding, which is what most published SQL style guides call for:
|
|
130
|
+
|
|
131
|
+
```sql
|
|
132
|
+
FROM customers cust
|
|
133
|
+
INNER JOIN orders ord ON ord.customer_id = cust.customer_id
|
|
134
|
+
LEFT JOIN order_line_items line_items ON line_items.order_id = ord.order_id
|
|
135
|
+
LEFT JOIN shipping_addresses addr ON addr.order_id = ord.order_id
|
|
136
|
+
AND addr.address_type = 'shipping'
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Install
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
uv tool install . # installs the `sqlalign` command
|
|
143
|
+
# or, for development:
|
|
144
|
+
uv sync # create the venv with dev deps (pytest, sqlfluff)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Requires Python ≥ 3.12. Runtime dependency: `sqlglot` (pinned to the 30.14.x
|
|
148
|
+
line — the layout engine depends on exact AST shapes; see `pyproject.toml`).
|
|
149
|
+
|
|
150
|
+
## Usage
|
|
151
|
+
|
|
152
|
+
```sh
|
|
153
|
+
sqlalign query.sql # format in place (rewrites the file)
|
|
154
|
+
sqlalign . # every *.sql under here, recursively
|
|
155
|
+
sqlalign --stdout query.sql # print the formatted result, leave the file
|
|
156
|
+
sqlalign --check *.sql # exit non-zero if any file is not formatted
|
|
157
|
+
sqlalign --dialect redshift ddl.sql
|
|
158
|
+
sqlalign --dialect tsql query.sql # SQL Server: TOP, [brackets]
|
|
159
|
+
sqlalign --width 120 query.sql
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Before → after
|
|
163
|
+
|
|
164
|
+
Input (`tests/fixtures/input/13.sql`):
|
|
165
|
+
|
|
166
|
+
```sql
|
|
167
|
+
-- #13: multi-character aliases (mixed lengths)
|
|
168
|
+
select cust.customer_id, cust.email, ord.order_id, ord.total, line_items.product_id, line_items.quantity, addr.city from customers cust inner join orders ord on ord.customer_id = cust.customer_id left join order_line_items line_items on line_items.order_id = ord.order_id left join shipping_addresses addr on addr.order_id = ord.order_id and addr.address_type = 'shipping' where ord.order_date >= '2026-07-01' and cust.segment = 'enterprise';
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Output:
|
|
172
|
+
|
|
173
|
+
```sql
|
|
174
|
+
-- #13: multi-character aliases (mixed lengths)
|
|
175
|
+
SELECT cust.customer_id
|
|
176
|
+
, cust.email
|
|
177
|
+
, ord.order_id
|
|
178
|
+
, ord.total
|
|
179
|
+
, line_items.product_id
|
|
180
|
+
, line_items.quantity
|
|
181
|
+
, addr.city
|
|
182
|
+
FROM customers cust
|
|
183
|
+
INNER JOIN orders ord ON ord.customer_id = cust.customer_id
|
|
184
|
+
LEFT JOIN order_line_items line_items ON line_items.order_id = ord.order_id
|
|
185
|
+
LEFT JOIN shipping_addresses addr ON addr.order_id = ord.order_id
|
|
186
|
+
AND addr.address_type = 'shipping'
|
|
187
|
+
WHERE ord.order_date >= '2026-07-01'
|
|
188
|
+
AND cust.segment = 'enterprise';
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## dbt / Jinja
|
|
192
|
+
|
|
193
|
+
Templated SQL isn't valid SQL, so most formatters decline it. sqlalign masks each
|
|
194
|
+
template expression with a **same-width** placeholder, formats normally, then puts
|
|
195
|
+
the original back — so alignment is computed against the real text width:
|
|
196
|
+
|
|
197
|
+
```sql
|
|
198
|
+
SELECT o.id
|
|
199
|
+
, o.total
|
|
200
|
+
FROM {{ ref('orders') }} o
|
|
201
|
+
JOIN {{ ref('customers') }} c ON c.id = o.customer_id
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
`{{ … }}`, `{% … %}` and `{# … #}` are recognised. An expression too short to hold
|
|
205
|
+
a unique placeholder (`{{x}}`) makes the file pass through untouched rather than be
|
|
206
|
+
approximated. Turn it off with `--no-protect-templating`.
|
|
207
|
+
|
|
208
|
+
## Configuration
|
|
209
|
+
|
|
210
|
+
Commit your team's style rather than passing flags every time. sqlalign reads a
|
|
211
|
+
`.sqlalign.toml`, or a `[tool.sqlalign]` table in `pyproject.toml`, discovered by
|
|
212
|
+
walking up from each file being formatted — so a repo can hold one config at its
|
|
213
|
+
root and a subdirectory can override it.
|
|
214
|
+
|
|
215
|
+
```toml
|
|
216
|
+
# .sqlalign.toml
|
|
217
|
+
width = 100 # 0 turns wrapping off
|
|
218
|
+
align = true
|
|
219
|
+
align_targets = ["aliases", "operators", "join_conditions"]
|
|
220
|
+
comma_position = "leading" # or "trailing"
|
|
221
|
+
boolean_operator_position = "leading" # or "trailing"
|
|
222
|
+
on_placement = "inline" # or "own_line"
|
|
223
|
+
format_dollar_bodies = true
|
|
224
|
+
protect_templating = true # mask Jinja/dbt before formatting
|
|
225
|
+
exclude = ["vendor/*", "*.gen.sql"]
|
|
226
|
+
# blank_lines_between_statements = 1 # unset = one blank line only between
|
|
227
|
+
# # two multi-line statements
|
|
228
|
+
neq_style = "!=" # or "<>"
|
|
229
|
+
decimal_style = "NUMERIC" # or "DECIMAL"
|
|
230
|
+
keyword_case = "upper" # or "lower"
|
|
231
|
+
table_alias_style = "bare" # or "as" -> FROM orders AS o
|
|
232
|
+
select_placement = "inline" # or "own_line"
|
|
233
|
+
select_indent = 2 # when the list starts below SELECT
|
|
234
|
+
clause_keyword_align = "left" # or "river"
|
|
235
|
+
body_blank_lines = 1 # inside a $$ body
|
|
236
|
+
river_gutter = 6
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Start from a **preset** and override what you want:
|
|
240
|
+
|
|
241
|
+
| Preset | What it is |
|
|
242
|
+
|---|---|
|
|
243
|
+
| `house` | the columnar default — aligned, leading separators, `ON` inline |
|
|
244
|
+
| `compact` | same line structure, no alignment padding (9 of 10 style guides are unpadded) |
|
|
245
|
+
| `trailing` | keeps the alignment, moves commas and `AND`/`OR` to end of line |
|
|
246
|
+
| `dbt` | lowercase keywords, list stacked under a bare `select` at 4, trailing commas, no padding (one deviation: a CTE body indents 2, not 4) |
|
|
247
|
+
| `river` | [Holywell's guide](https://www.sqlstyle.guide/) — root keywords right-aligned to a 6-column gutter, joins on the far side of it, otherwise unpadded |
|
|
248
|
+
| `gitlab` | [GitLab's published guide](https://handbook.gitlab.com/handbook/enterprise-data/platform/sql-style-guide/) — list stacked at 2, trailing commas, `ON` on its own line, `AS` on table aliases, and column aliases the only thing aligned |
|
|
249
|
+
|
|
250
|
+
```toml
|
|
251
|
+
preset = "compact"
|
|
252
|
+
comma_position = "trailing" # layers on top of the preset
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Precedence is **built-in defaults → preset → config file → command-line flags**.
|
|
256
|
+
`sqlalign --show-config file.sql` prints the effective settings (as TOML you can
|
|
257
|
+
paste into a config) and says which file they came from. `--isolated` ignores any
|
|
258
|
+
config; `--config PATH` uses a specific one.
|
|
259
|
+
|
|
260
|
+
An unknown key is an **error**, not a silent no-op — a typo in a committed config
|
|
261
|
+
would otherwise mean a team believes it has a setting it doesn't have.
|
|
262
|
+
`--no-strict-config` downgrades that to a warning.
|
|
263
|
+
|
|
264
|
+
## Flags
|
|
265
|
+
|
|
266
|
+
| Flag | Default | Effect |
|
|
267
|
+
|------|---------|--------|
|
|
268
|
+
| `files …` | — | files or directories (a directory is searched recursively for `*.sql`) |
|
|
269
|
+
| `--exclude GLOB` | none | skip files matching this glob (repeatable; also `exclude` in config) |
|
|
270
|
+
| `--blank-lines-between-statements N` | auto | force N blank lines between every pair of statements |
|
|
271
|
+
| `--check` | off | write nothing; name the files that would change; exit `1` if any would |
|
|
272
|
+
| `--diff` | off | write nothing; print a unified diff of what would change; exit `1` if any would |
|
|
273
|
+
| `--stdout` | off | write the result to stdout instead of rewriting the file |
|
|
274
|
+
| `--dialect {postgres,redshift,tsql}` | `postgres` | parse/emit dialect |
|
|
275
|
+
| `--width N` | `100` | target line width for wrapping decisions; `0` turns wrapping off |
|
|
276
|
+
| `--no-align` | off | emit one space between tokens instead of padding them into columns — same line structure, no alignment |
|
|
277
|
+
| `--align-targets a,b,…` | all but `table_names` | which alignment columns to keep (see below) |
|
|
278
|
+
| `--line-ending {auto,lf,crlf}` | `auto` | line endings to write; `auto` preserves each file's own |
|
|
279
|
+
| `--comma-position {leading,trailing}` | `leading` | where the separator comma sits in a stacked list |
|
|
280
|
+
| `--boolean-operator-position {leading,trailing}` | `leading` | where `AND`/`OR` sit when a predicate spans lines |
|
|
281
|
+
| `--on-placement {inline,own_line}` | `inline` | whether a JOIN's `ON` rides the table line or drops below it |
|
|
282
|
+
| `--no-format-bodies` | off | leave dollar-quoted (`$$`) procedure/function bodies untouched |
|
|
283
|
+
| `--no-protect-templating` | off | don't mask Jinja/dbt template expressions |
|
|
284
|
+
| `--neq-style {!=,<>}` | `!=` | spelling for the not-equal operator |
|
|
285
|
+
| `--decimal-style {NUMERIC,DECIMAL}` | `NUMERIC` | spelling for the NUMERIC/DECIMAL type |
|
|
286
|
+
| `--table-alias-style {bare,as}` | `bare` | print a table alias as `t a` or `t AS a` |
|
|
287
|
+
| `--select-placement {inline,own_line}` | `inline` | whether the first select item rides the `SELECT` line |
|
|
288
|
+
| `--select-indent N` | `2` | columns the select list indents when it starts below `SELECT` |
|
|
289
|
+
| `--clause-keyword-align {left,river}` | `left` | right-align root clause keywords to a gutter |
|
|
290
|
+
| `--river-gutter N` | `6` | the column a river aligns them to |
|
|
291
|
+
| `--keyword-case {upper,lower}` | `upper` | case for keywords, function names and types |
|
|
292
|
+
| `--preset {compact,dbt,gitlab,house,river,trailing}` | `house` | named starting point (flags and config keys layer on top) |
|
|
293
|
+
| `--config PATH` | discovered | use a specific config file |
|
|
294
|
+
| `--isolated` | off | ignore any config file |
|
|
295
|
+
| `--print-sqlfluff-config` | — | print a `.sqlfluff` that lets sqlfluff run alongside sqlalign, and exit |
|
|
296
|
+
| `--lint` | off | after formatting, run sqlfluff over the result (needs `pip install 'sqlalign[lint]'`) |
|
|
297
|
+
| `--body-blank-lines N` | `1` | blank lines between the elements of a `$$` body |
|
|
298
|
+
| `--gui` | — | *(experimental)* open a settings panel with a live preview, and exit |
|
|
299
|
+
| `--report` | off | print a coverage summary: how many statements formatted, and what the rest declined on |
|
|
300
|
+
| `--max-declines N` | — | exit 1 if more than N statements pass through unformatted (implies `--report`) |
|
|
301
|
+
| `--show-config` | off | print effective settings as TOML and exit |
|
|
302
|
+
| `--no-strict-config` | off | warn on unknown config keys instead of failing |
|
|
303
|
+
|
|
304
|
+
`--neq-style` and `--decimal-style` exist because sqlglot's parser collapses each
|
|
305
|
+
of those pairs to a single node, so a spelling has to be chosen when printing.
|
|
306
|
+
They are the *only* two places sqlalign picks for you — everything the parser
|
|
307
|
+
preserves is passed through as written.
|
|
308
|
+
|
|
309
|
+
`--check` and `--stdout` are mutually exclusive. Exit codes: `0` success (or
|
|
310
|
+
`--check` clean); `1` a `--check` file differs; `2` an unreadable file or a
|
|
311
|
+
safety abort (other files in the same run still process).
|
|
312
|
+
|
|
313
|
+
## Linting inside `$$` bodies
|
|
314
|
+
|
|
315
|
+
sqlfluff cannot lint a plpgsql body — to its parser the whole body is one string
|
|
316
|
+
literal, so a function full of badly-written SQL passes clean. `--lint` closes
|
|
317
|
+
that: sqlalign already locates those statements in order to format them, so it
|
|
318
|
+
hands them to sqlfluff too, and a finding's line and column are the real ones.
|
|
319
|
+
|
|
320
|
+
```console
|
|
321
|
+
$ sqlalign --check --lint report.sql
|
|
322
|
+
L: 1 | P: 17 | CP03 | Function names must be upper case.
|
|
323
|
+
All Finished!
|
|
324
|
+
== [report.sql] inside $$ bodies (sqlfluff cannot reach these on its own)
|
|
325
|
+
L: 8 | P: 1 | AM04 | Query produces an unknown number of result columns. [ambiguous.column_count]
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
See the [guide](docs/guide/getting-started.md) for how it works and what it does
|
|
329
|
+
not cover.
|
|
330
|
+
|
|
331
|
+
## Guarantees & scope
|
|
332
|
+
|
|
333
|
+
- **Byte-for-byte golden fixtures** — 25 hand-formatted samples in
|
|
334
|
+
`tests/fixtures/expected/` are the executable specification of the style; the
|
|
335
|
+
suite asserts `format(input) == expected` for every one, plus idempotency
|
|
336
|
+
(`format(expected) == expected`) and AST-equivalence.
|
|
337
|
+
- **sqlfluff lint gate** — every standard-SQL Postgres expected fixture lints
|
|
338
|
+
clean under `.sqlfluff`. Three rules the house style deliberately conflicts
|
|
339
|
+
with are excluded there, each documented: `ambiguous.column_references` (the
|
|
340
|
+
source GROUP BY reference form is preserved), `aliasing.expression` (aliases
|
|
341
|
+
are not forced), and `convention.casting_style` (`::` vs `CAST(...)` is
|
|
342
|
+
preserved as written). The Redshift and plpgsql fixtures in
|
|
343
|
+
`samples/queries.sql` are outside the gate (dialect / linter-model limits) —
|
|
344
|
+
see `tests/test_sqlfluff_gate.py`.
|
|
345
|
+
- **v1 limitations** — constructs the engine does not model (e.g. some `MERGE`
|
|
346
|
+
variants, cursors/`FOR` loops in plpgsql bodies, comments buried inside an
|
|
347
|
+
expression) pass through byte-identical with a warning rather than being
|
|
348
|
+
reformatted. This is by design: correctness over coverage.
|
|
349
|
+
|
|
350
|
+
## Adding a new golden sample
|
|
351
|
+
|
|
352
|
+
The fixtures are the spec — grow them, never weaken them:
|
|
353
|
+
|
|
354
|
+
1. Add the **hand-formatted** query to `samples/queries.sql` under a new
|
|
355
|
+
`-- #N: description` header.
|
|
356
|
+
2. Regenerate the split fixtures: `python scripts/build_fixtures.py samples/queries.sql tests/fixtures/expected`.
|
|
357
|
+
Add the corresponding messy `tests/fixtures/input/N.sql`.
|
|
358
|
+
3. Run `PYTHONPATH=src pytest -q`. If the new golden fails, either the sample
|
|
359
|
+
exposes a real gap (fix the layout handler) or it's an unmodeled construct
|
|
360
|
+
(it should pass through — confirm the warning, not a wrong render).
|
|
361
|
+
4. If the new expected output should lint clean, confirm the sqlfluff gate still
|
|
362
|
+
passes (or document a new exclusion in `.sqlfluff` with a comment).
|
|
363
|
+
|
|
364
|
+
## Documentation
|
|
365
|
+
|
|
366
|
+
The [settings reference](docs/v1/settings.html) is the page to start with: it
|
|
367
|
+
shows every setting with the same SQL rendered under each of its values.
|
|
368
|
+
|
|
369
|
+
To read the site locally:
|
|
370
|
+
|
|
371
|
+
```sh
|
|
372
|
+
python3 -m http.server -d docs 8000 # then open http://localhost:8000/
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
**The site is generated and committed.** There is no CI and GitHub Pages runs no
|
|
376
|
+
build step, so the HTML in `docs/v1/` is what ships. Prose is authored in
|
|
377
|
+
`docs/guide/*.md`; every configuration example is produced by *running the
|
|
378
|
+
formatter* at build time, so no example on the site can drift from what the tool
|
|
379
|
+
does. After editing a guide page, a setting, or anything that changes output:
|
|
380
|
+
|
|
381
|
+
```sh
|
|
382
|
+
uv run python tools/build_docs.py # rebuild docs/v1/
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
`tests/test_docs_site.py` fails if the committed site does not match what the
|
|
386
|
+
generator produces, so a forgotten rebuild cannot ship.
|
|
387
|
+
|
|
388
|
+
Versions are directories. `docs/v1/` is the only one today; a new version means
|
|
389
|
+
building into a new directory and adding it to `VERSIONS` in the generator.
|
|
390
|
+
Nothing in a built page points outside its own version, so an old one keeps
|
|
391
|
+
working untouched.
|
|
392
|
+
|
|
393
|
+
## Contributing
|
|
394
|
+
|
|
395
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). In short: `uv sync`, then `uv run pytest
|
|
396
|
+
-q` and `uv run ruff check .` must both be clean. The goldens in
|
|
397
|
+
`tests/fixtures/expected/` are the specification, not snapshots.
|
|
398
|
+
|
|
399
|
+
Release notes are in [CHANGELOG.md](CHANGELOG.md).
|
|
400
|
+
|
|
401
|
+
## Reference
|
|
402
|
+
|
|
403
|
+
- **Style reference:** `samples/queries.sql` — the hand-formatted goldens.
|
|
404
|
+
- **Lint config:** `.sqlfluff`.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
sqlalign/__init__.py,sha256=f0XHp1fXFgh6edJswAhQ9IBQl1TsI_BvQZZKBV3kH6Y,536
|
|
2
|
+
sqlalign/align.py,sha256=RzjlWERxjq9aNGhPA-E_TjS-5ntnOFEKiXzwBqFEfk4,7236
|
|
3
|
+
sqlalign/bodylint.py,sha256=lBmEIOkAQNWov8X4O9T4ynH4nOUiAsWrFomWSQkc6VQ,5085
|
|
4
|
+
sqlalign/casing.py,sha256=w97se03KoCe7V5y6UzKyepjxWZtSucGoBCpVBN0kb40,7866
|
|
5
|
+
sqlalign/cli.py,sha256=0phCBZjv2bEPYH5KLM-thnUJFHnrgFsNtjpO9XrME4k,17948
|
|
6
|
+
sqlalign/commas.py,sha256=vJ0CXVpAvCrhrnkwk6o5U6y6o1TeJZ-mhKaz-w2xJdA,2855
|
|
7
|
+
sqlalign/config.py,sha256=VVfP9jPKAkRjim6ydUY4LhZTUv3lvKIrKU2McPR8faU,1063
|
|
8
|
+
sqlalign/configfile.py,sha256=74rjIl5mGJSyIn7bwO0aeKe7HOm-qN6pB4byz-L2JRE,8672
|
|
9
|
+
sqlalign/formatter.py,sha256=hgPKbqgCqhBFUKf_AKluUiJIFeMLApinemy1wxnyoYg,31079
|
|
10
|
+
sqlalign/gui.py,sha256=6GCC5eMD_SvdkbtkWjcW8rF-tysQHji4HJ4mch55l1Q,31039
|
|
11
|
+
sqlalign/ir.py,sha256=cHKTXgGOuOJgFQwsO7lTzVtca1ZKP-PFZYxybhKgmrY,1161
|
|
12
|
+
sqlalign/keywordcase.py,sha256=UA054AOnLVvVZCw6J4nzOKC73CY2xP6kOAUFCG-pgf4,5497
|
|
13
|
+
sqlalign/lint.py,sha256=ISuo60vjWdz8hDK_bwXjdibSZ-RaAytIHl-bTtX7yhk,7444
|
|
14
|
+
sqlalign/plpgsql.py,sha256=OPUo1rusB_HwH59jaHVfkp41S1C4wMWav9--3GeSu20,17547
|
|
15
|
+
sqlalign/splitter.py,sha256=gkp-yU9HNkC1lT7c3OwLYnFZUSAoyfihpaFxD3dhS0A,9821
|
|
16
|
+
sqlalign/sqlfluffconfig.py,sha256=yeK5zq9pGFblFOCPo70DCmbOPd7ARxasQlQbRhoJ2n4,4652
|
|
17
|
+
sqlalign/style.py,sha256=LjCxfOD--GVyDus1h99WyGJfQr1yDjIDVXntabvHJM0,11599
|
|
18
|
+
sqlalign/templating.py,sha256=o8J83gYH1PoabmbLjOSYIVLOpUrimzmPsd-oGp_pt6U,3793
|
|
19
|
+
sqlalign/layout/__init__.py,sha256=579cugPzcjKLruNwX8SbkUyWNu-r_t1s1eJJzPTf7cE,14436
|
|
20
|
+
sqlalign/layout/case.py,sha256=3iBR05sL9QIEb3NtO482BM0sRLSKGOkrKTNT8LCJnaE,12468
|
|
21
|
+
sqlalign/layout/comments.py,sha256=PwvrR-SQZOIs85-o-CslwAR6nH-DwkAiDBYBNJuIZfI,21348
|
|
22
|
+
sqlalign/layout/conditions.py,sha256=jf2filUbE6k-6BFrSYpN1tNnxtz-rC7oZlwC6bb0unw,17964
|
|
23
|
+
sqlalign/layout/cte.py,sha256=C1XUvtkVBKQDpL7j1i2wY0hXwl7ejNCtn34MAa9MnY0,3642
|
|
24
|
+
sqlalign/layout/ddl.py,sha256=i7dG57-1grXteshg9fnbVQYGDj92OgrVB5QT9hP6TqU,18469
|
|
25
|
+
sqlalign/layout/dml.py,sha256=eDLTG2Os1B_s385mRGplyag8Z5mB3fUNCKF66yx3Baw,12906
|
|
26
|
+
sqlalign/layout/expr.py,sha256=Uh7JvZ7rKc-oH5GAfChd2Wl3DaEUdU5bFA-fyuvVjrs,5754
|
|
27
|
+
sqlalign/layout/fromjoin.py,sha256=J5MLQClX6ajqMVIwmC4vrwkFex9b99JO19lIJqhlVw4,16422
|
|
28
|
+
sqlalign/layout/grouporder.py,sha256=LrmZb3oPBX6NpiH9TqFnZT6NTOfPbyBipE1kkMZhQSM,6552
|
|
29
|
+
sqlalign/layout/select.py,sha256=PHE4wuTScaJCpkZehvqaFLk_EqRlZYH7PdNTBFYk7bo,27388
|
|
30
|
+
sqlalign/layout/setop.py,sha256=hjve3Qxi2CsaFEwijg6srhfMdEUlv2b9MmOUp6BNip0,3427
|
|
31
|
+
sqlalign/layout/subquery.py,sha256=IIi4Cy8ZQ3WNBmPvmifuTRofXcWibakHCaaj9Uh2MfA,12496
|
|
32
|
+
sqlalign/layout/window.py,sha256=X8YJ32hQGriwRQsDM2ZDvmaU6YHunJvcMi7UShmGJrU,9943
|
|
33
|
+
sqlalign-1.0.1.dist-info/METADATA,sha256=bwfIxQFiqKNyajVXJavmEw4ia3TbP6debD8MyWJq6zA,19691
|
|
34
|
+
sqlalign-1.0.1.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
35
|
+
sqlalign-1.0.1.dist-info/entry_points.txt,sha256=pHPkRH7HQwwvx1mdDjdvGZ_xMXMg0gaWtTOmvrONPuc,47
|
|
36
|
+
sqlalign-1.0.1.dist-info/licenses/LICENSE,sha256=qvo2BvsFUcC3_3LOk36ZKcaMp_j1AFMfBoCNRFcyrco,1076
|
|
37
|
+
sqlalign-1.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pavan Amin (Lumaru)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|