Metadata-Version: 2.4
Name: sqlfluff-tstring
Version: 0.1.1
Summary: Auto-format SQL inside Python t-strings using sqlfluff
Keywords: formatter,linter,sql,sqlfluff,t-string
Author: Krzysztof Żuraw
License-Expression: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Dist: sqlfluff>=4.0.4
Requires-Python: >=3.14
Project-URL: Homepage, https://github.com/kzuraw/sqlfluff-tstring
Project-URL: Issues, https://github.com/kzuraw/sqlfluff-tstring/issues
Project-URL: Repository, https://github.com/kzuraw/sqlfluff-tstring
Description-Content-Type: text/markdown

# sqlfluff-tstring

Auto-format SQL inside Python t-strings using [sqlfluff](https://sqlfluff.com/).

Finds `sql(t"...")` calls in `.py` files and formats the embedded SQL, preserving interpolations and respecting your `.sqlfluff` config.

Requires Python 3.14+ (PEP 750 t-strings).

## Installation

```bash
pip install sqlfluff-tstring
```

## Usage

```bash
# Format files in-place
sqlfluff-tstring src/

# Check mode (exit 1 if changes needed, for CI)
sqlfluff-tstring --check src/

# Show diff without writing
sqlfluff-tstring --diff src/

# Override SQL dialect
sqlfluff-tstring --dialect postgres src/

# Use a specific .sqlfluff config file
sqlfluff-tstring --config path/to/.sqlfluff src/
```

## What it does

Given a file like:

```python
from sql_tstring import sql

query = sql(t"select   *   from   users   where   id = {uid}   and   name = {name}")
```

Running `sqlfluff-tstring` produces:

```python
from sql_tstring import sql

query = sql(t"""
select * from users
where id = {uid} and name = {name}
""")
```

- Interpolations (`{uid}`, `{name!r}`, `{val:.2f}`) are preserved through formatting
- Single quotes auto-upgrade to triple quotes when sqlfluff introduces newlines
- Multiline content in triple-quoted t-strings is wrapped with leading/trailing newlines
- Supports `sql(t"...")` and `obj.sql(t"...")` call patterns
- Respects your `.sqlfluff` configuration for dialect and rules

## CLI options

```
sqlfluff-tstring [OPTIONS] [PATHS...]

positional arguments:
  paths              Files or directories to format (default: .)

options:
  --check            Exit 1 if changes needed (CI mode)
  --diff             Show diff, don't write changes
  --config PATH      Path to .sqlfluff config file
  --dialect DIALECT  Override SQL dialect
  -v, --verbose      Show unchanged files
  -q, --quiet        Suppress all output
```

Exit codes: `0` = success/no changes, `1` = changes needed (check mode).

## Development

```bash
uv sync
uv run pytest
uv run ruff check src/ tests/
uv run ty check src/
```
