/sqlty:sqltyfrom sqlty
Writes, types, and checks raw SQL in Python using sqlty. Infers Python row types from queries and schema, wraps them as SQL[T] subclasses, and validates queries against migrations.
Ships in sqlty. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
sqlty infers the Python row type of each SQL query from the query and the
project's schema, writes it as SQL[T], and checks it. SQL[T] is a str
subclass: it works wherever a string query works.
Run sqlty version: this skill may be newer or older than the installed sqlty.
When it and sqlty --help or sqlty rule NAME disagree, trust the command.
Read [tool.sqlty] in pyproject.toml first. dialect (default postgres)
and schema (SQL files with CREATE TABLE, or migrations) decide every type.
| Task | Skill |
|---|---|
Write or edit a query; add or remove SQL[T] wrappers | sqlty-rewrite |
| Read a diagnostic, name a row type, check parameters | sqlty-check |
| Change a table, write a migration, plan a rename | sqlty-breaking |
| Set up or repair pre-commit or CI | sqlty-ci |
| Run sqlty in VS Code or another editor | sqlty-server |
| Introduce sqlty into a project that doesn't use it | sqlty-adopt |
sqlty skill NAME prints a skill that isn't installed.
--sql markersqlty reads only strings whose first line is --sql, followed by a newline.
With a space, the whole query is a SQL comment and nothing is checked:
right = "--sql\nSELECT id::INTEGER FROM users"
wrong = "--sql SELECT id::INTEGER FROM users"
# rewritten: right = SQL[tuple[int]]("--sql\nSELECT id::INTEGER FROM users")
# rewritten: wrong = "--sql SELECT id::INTEGER FROM users"
In a triple-quoted string, end the first line after --sql:
q = """--sql
SELECT id::INTEGER, name::TEXT FROM users"""
# rewritten: q = SQL[tuple[int, str]]("""--sql
# rewritten: SELECT id::INTEGER, name::TEXT FROM users""")
sqlty rewrite app/queries.py # wrap new --sql strings as SQL[T]
sqlty check app/ # report what doesn't fit
Never hand-write a guessed T: let rewrite infer it, then name it (see
sqlty-check). A query rewrite leaves alone has a column sqlty cannot type.
SQL[T] only types the string; pass it to the driver as usual, or use
sqlty.drivers.psycopg.execute to get typed rows.+, % or an f-string loses the type and is not
checked (fstring-skipped). Pass values as parameters (%s, $1, ?).SQLTemplate[T]; psycopg's {x:i}, {x:l} and
{part:q} fields are read in modules that import psycopg.DATE is str and a NUMERIC
a float. See Type mapping before "fixing" a type.In Go, a query is sqlty.SQL[R, P] from github.com/jirikuncar/sqlty/go: R the row
struct, P a func type naming the parameters. sqlty-vet checks it under go vet,
reading the same sqlty.toml or [tool.sqlty]:
var GetUser = sqlty.SQL[User, func(email string)](`
SELECT id, email, name FROM users WHERE email = $1`)
user, err := pgxq.One(ctx, conn, GetUser, "[email protected]") // user is User
A NULL-able column needs a pointer, sql.Null* or pgtype field; sqlty.NoRows is the R
of a statement without rows and sqlty.NoParams the P of a query without parameters.
brew install jirikuncar/sqlty/sqlty-vet installs it (Linux and macOS), or make go-vet
builds it from a checkout; run go vet -vettool=$(which sqlty-vet) ./.... See
Go.
The documentation is at https://sqlty.kuncar.dev/:
sqlty.SQL[R, P] checked in go vetsqlty rule NAME prints its page; all rulesWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub jirikuncar/sqlty --plugin sqlty7 skills in this plugin
/sqlty-adoptIntroduce sqlty into an existing Python project with raw SQL queries, one module at a time. Use when a project doesn't use sqlty yet and you are asked to add it, type its SQL queries, configure [tool.sqlty] (dialect, schema from a database dump or migrations), choose which queries to convert first, mark the ones sqlty can't type yet, or add the first CI gate./sqlty-breakingCheck that a schema change or migration doesn't break the queries running during a rolling deploy, with sqlty breaking, and plan an expand and contract migration. Use when adding, dropping, renaming or changing a table or column, writing a migration, making a column nullable or NOT NULL, reading a sqlty breaking finding (backward or forward), or splitting a schema change into safe pull requests./Other plugins' skills for the same job