Przejdź do treści
Biblioteka skilli
Programowanie · Konwersja i formaty

sqlty-rewrite

/sqlty-rewrite

Opakowuje zapytania SQL w Pythonie w wrappery SQL[T] przez sqlty rewrite i utrzymuje je po każdej edycji zapytania.

Repozytorium
sqlty ↗
Licencja
MIT
Ostatnia zmiana repozytorium
27.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
4
Przestarzałość

Brak sygnałów. Repozytorium zmienione 27.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Opakowuje zapytania SQL w Pythonie w wrappery SQL[T] przez sqlty rewrite i utrzymuje je po każdej edycji zapytania.

Wyzwalacze z opisu

coding sqlty
Oryginalny opis (EN)

Wrap --sql query strings as SQL[T] with sqlty rewrite, update or remove the wrappers, and keep them in sync after editing a query. Use when writing a new SQL query in Python, editing the SQL inside an SQL[T] wrapper, committing or removing wrappers (sqlty rewrite, sqlty strip, --check, --diff), choosing an import-style, wrapping untyped queries as SQL[UNTYPED], or using the sqlty magic codec (a "coding sqlty" source encoding) instead of committed wrappers.

Jak działa

  1. Write a new query
  2. What rewrite leaves alone
  3. Edit a wrapped query
  4. Check without writing
  5. Import style
  6. The magic codec
  7. Reference
Sekcje z nagłówków SKILL.md, w oryginale · 131 linii, 633 słów
Podgląd SKILL.md
---
name: sqlty-rewrite
description: Wrap --sql query strings as SQL[T] with sqlty rewrite, update or remove the wrappers, and keep them in sync after editing a query. Use when writing a new SQL query in Python, editing the SQL inside an SQL[T] wrapper, committing or removing wrappers (sqlty rewrite, sqlty strip, --check, --diff), choosing an import-style, wrapping untyped queries as SQL[UNTYPED], or using the sqlty magic codec (a "coding sqlty" source encoding) instead of committed wrappers.
---

# sqlty rewrite

`sqlty rewrite` wraps each `--sql` string as `SQL[T]("--sql\n...")`, with `T`
the inferred row type, and adds the import. `sqlty strip` removes the wrappers.
Neither changes the string itself.

Run `sqlty version`: this skill may be newer or older than the installed sqlty.
When it and `sqlty --help` disagree, trust the command.

## Write a new query

1. Start the string with `--sql` and a newline.
2. Run `sqlty rewrite <file>`.
3. Run `sqlty check <file>`. It must report nothing.

```python
user_id = 1
q = "--sql\nSELECT id::INTEGER, name::TEXT FROM users WHERE id = %s"
# rewritten: user_id = 1
# rewritten: q = SQL[tuple[int, str]]("--sql\nSELECT id::INTEGER, name::TEXT FROM users WHERE id = %s")
```

## What `rewrite` leaves alone

| String | Why |
|--------|-----|
| `INSERT`, `UPDATE`, `DELETE` without `RETURNING`; DDL | returns no rows |
| SQL the parser rejects | no type to infer; `sqlty check` reports it |
| a column sqlty can't type | an unknown table or function, `SELECT *` without a schema |
| f-strings, `+`, `%` | not a literal; pass values as parameters |

Make the column typeable: cast it (`x::INTEGER`, `CAST(x AS INTEGER)`) or add the
table to the schema. Don't hand-write a guessed `T`.

```python
unknown = "--sql\nSELECT x FROM t"
typed = "--sql\nSELECT x::INTEGER FROM t"
# rewritten: unknown = "--sql\nSELECT x FROM t"
# rewritten: typed = SQL[tuple[int]]("--sql\nSELECT x::INTEGER FROM t")
```

### Mark untyped queries

With `untyped = "sentinel"`, a query whose row type is unknown becomes
`SQL[UNTYPED]`, so it is visible and `sqlty check --fix` types it once it can:

```toml
[tool.sqlty]
untyped = "sentinel"
```

```python
pairs = "--sql\nSELECT x, y FROM pairs"
# rewritten: pairs = SQL[UNTYPED]("--sql\nSELECT x, y FROM pairs")
```

`sqlty rewrite --untyped sentinel` does the same for one run.

## Edit a wrapped query

`rewrite` never replaces an existing wrapper. After changing the SQL inside
`SQL[T](...)`, run `sqlty check --fix`: it rewrites every stale `SQL[tuple[...]]`
and `SQL[UNTYPED]`, and leaves named row types for you to update.

```python
from sqlty import SQL

q = SQL[tuple[int, str]]("--sql\nSELECT id::INTEGER, name::TEXT, email::TEXT FROM users")
# fixed: from sqlty import SQL
# fixed:
# fixed: q = SQL[tuple[int, str, str]]("--sql\nSELECT id::INTEGER, name::TEXT, email::TEXT FROM users")
```

Don't strip and rewrite a file to update it: `strip` removes every wrapper,
`SQL[User]` included, and the next `rewrite` writes `SQL[tuple[...]]`.

```python
user = SQL[User]("--sql\nSELECT id::INTEGER FROM users")
# stripped: user = "--sql\nSELECT id::INTEGER FROM users"
```

## Check without writing

| Command | Exits 1 when |
|---------|--------------|
| `sqlty rewrite --check .` | a file would be rewritten |
| `sqlty rewrite --diff .` | a file would be rewritten; prints the diff |
| `sqlty strip --check .` | a file still has wrappers |

For a file whose `--sql` strings are all plain, `strip(rewrite(x)) == x`.

## Import style

`import-style` changes the import line and the wrapper name:

```toml
[tool.sqlty]
import-style = "from sqlty import SQL as Q"
```

```python
query = "--sql\nSELECT id::INTEGER FROM users"
# rewritten-file: from sqlty import SQL as Q
# rewritten-file: query = Q[tuple[int]]("--sql\nSELECT id::INTEGER FROM users")
```

## The magic codec

A file whose first or second line is `# coding: sqlty` is rewritten when Python
reads it, so it runs with wrappers that aren't on disk. Type checkers read the
file on disk, so they don't see the types: use it for scripts and notebooks,
and `sqlty rewrite` for code you commit.

```python
# coding: sqlty

query = "--sql\nSELECT id::INTEGER, name::TEXT FROM users"
# decoded: query = SQL[tuple[int, str]]("--sql\nSELECT id::INTEGER, name::TEXT FROM users")
```

`SyntaxError: unknown encoding: sqlty` means the codec isn't registered: in an
editable install, `import sqlty.magic` before the first such module.

## Reference

- [Writing queries](https://jirikuncar.github.io/sqlty/guide/writing-queries/)
- [Untyped queries](https://jirikuncar.github.io/sqlty/guide/untyped/)
- [Magic codec](https://jirikuncar.github.io/sqlty/guide/magic-codec/)
- [CLI reference](https://jirikuncar.github.io/sqlty/reference/cli/)

Wersje

W bazie nie ma innych skilli o nazwie sqlty-rewrite.

Migawka bazy z 13.11.2026 · wersja paczki 6ee7d4504617 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100sqlty
    Pisze, typuje i sprawdza surowe zapytania SQL w Pythonie przy użyciu sqlty i kieruje do właściwego narzędzia.
  • 100sqlty-server
    Konfiguruje serwer sqlty i rozszerzenie do edytorów, aby podświetlał SQL, naprawiał zapytania przy zapisie i pokazywał ostrzeżenia.
  • 100sql-style-and-tuning
    Pisze SQL łatwy do czytania i przeglądania oraz przyspiesza wolne zapytania, czytając najpierw plan.
  • 90sql-optimization
    Stroi zapytania SQL, dobiera strategie indeksowania i analizuje plany EXPLAIN, gdy zapytania działają zbyt wolno.
  • 100sql
    Sprawdza, poprawia i przepisuje zapytania SQL w PostgreSQL, Spark SQL, T-SQL, BigQuery i Snowflake, także pod kątem kosztu.
  • 100sql-advanced
    Pomaga pisać złożone zapytania SQL: CTE, funkcje okna, zapytania rekurencyjne, optymalizacja i analiza EXPLAIN.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.