Repository navigation
v0.10.0 #1728
jirikuncar
announced in
Announcements
v0.10.0
#1728
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
sqlty 0.10.0 checks typed raw SQL in Go under
go vet, checks and types rustmy and asyncpg calls, and adds rules for NULL writes,UPDATEandDELETEwithoutWHERE, argument counts, duplicate output columns and repeated parameters. The language server gains completion of functions, keywords and enum values, signature help, go to definition and semantic tokens.Upgrading
errorby default):null-write: a literalNULLwritten to aNOT NULLcolumn, inINSERT,UPDATE,ON CONFLICT DO UPDATEandMERGE. PostgreSQL only; a table with aBEFORErow trigger is skipped (Report NULL written to a NOT NULL column #1534)argument-count-mismatch: a built-in called with an argument count that fits none of its overloads, and*passed to a function other thancount. Reported at the function name. Functions the schema defines, named arguments and table functions are not checked (Report calls with the wrong number of arguments #1434, Show SQLite function signatures #1558, Report SUBSTRING argument counts at the function name #1671)duplicate-column: a query read into a row mapped by name (TypedDict, dataclass, Pydantic,Protocol,dict) with two columns of one name. Alias one:p.id AS p_id(Report duplicate output column names #1529)set-column-count: aUNION,INTERSECTorEXCEPTbranch with another column count than the first (Report set operation branches with different column counts #1415)position-out-of-range: anORDER BYorGROUP BYposition that names no select item (Report ORDER BY and GROUP BY positions out of range #1418)column-alias-count: an alias list longer than the relation it renames, or shorter on MySQL and SQLite CTEs (Report column alias lists that do not fit the relation #1424)rejected-queryfor a parameter used twice with types of different categories, which PostgreSQL rejects:id = %(x)s OR name = %(x)s. SQLite reports nothing (Type repeated parameters and report the ones PostgreSQL rejects #1557)unknown-tablefor a qualifier that names noFROMitem:SELECT users.id FROM orgsandSELECT users.id FROM users AS u(Report a qualifier that names no FROM item #1398)param-type-mismatchfor astrliteral argument that PostgreSQL's input function for the parameter's type rejects ("abc"for an integer,"2026-02-30"for a date) and for an enum orCHECK (col IN (...))parameter given a value the column never holds (Check str literal parameters against PostgreSQL's input syntax #1403)params-type-mismatchandparam-type-mismatchnow also judge parameters of aCHAR(n)column whoseCHECKvalues are shorter thann; trailing spaces of both sides are ignored, as the server does (Compare Literal parameters of CHAR(n) columns without trailing spaces #1707, Judge parameters of CHAR(n) columns against CHECK values of other lengths #1710)ungrouped-columnnow judgesSELECT *overJOIN ... USINGandNATURAL JOINwithGROUP BY. AGROUP BYposition with*is no longer judged (Check ungrouped columns of SELECT * over JOIN USING #1701)position-out-of-rangemakesungrouped-columnsilent for that position (Report ORDER BY and GROUP BY positions out of range #1418)json-shape-mismatchnow checks the field types of a Pydantic model, not only its keys, with the conversions Pydantic performs: a lax field takes a JSON string for any scalar and a JSON integer forbool, a strict field (strictconfig,Field(strict=True),Strict*types) keeps theTypedDictrules. A number intostror an array into a scalar is reported (Check JSON field types against Pydantic model fields #1726)missing-where:UPDATEorDELETEwithoutWHERE, in queries and.sqlquery files.WHERE truemeans it. Migrations keepunbatched-backfill(Report UPDATE and DELETE without WHERE #1517)nullable-write: a value that can be NULL, such as a nullable column or aLEFT JOINcolumn, written to aNOT NULLcolumn. PostgreSQL only (Report NULL written to a NOT NULL column #1534)unused-cte: a CTE nothing reads. Editors fade it (Report a CTE the query never reads #1422)unknown-functionfor a table function inFROMthat is neither built in nor defined by the schema, with acheck --fixsuggestion (Report an unknown table function with a suggestion #1436)fanout-aggregateandunproven-joinnow see the key of a derived table with its ownWITH, so joins to it are judged where they were skipped (Find subquery output keys when the subquery has a WITH #1691)rewritewrites different parameter types than on 0.9.0, so your nextrewritechanges them:%s::intisint | Noneinstead oftyping.Any(Type repeated parameters and report the ones PostgreSQL rejects #1557)from datetime import datetime, parameter types readdatetime, notdatetime.datetime, and a class the module lacks is imported by name (Spell parameter types with the module's datetime binding #1505)CHAR(n)column whoseCHECKvalues all havencharacters isLiteral[...]instead ofstr:CHAR(1) CHECK (c IN ('Y', 'N'))isLiteral['Y', 'N']. A shorter value keepsstr.literal-writeandunmatched-literalignore trailing spaces on PostgreSQL (Type CHAR(n) CHECK values as Literal and compare them without padding #1546)text[][]istext, as the server types it (Type a subscript of a multi-dimensional PostgreSQL array as its element #1399)BIGINT UNSIGNEDisDecimal;JSON_TABLEcolumns underNESTED PATHare nullable (Agree with MySQL on oversized literals and NESTED PATH columns #1634);GROUP_CONCATand string functions ofBITor binary values returnbytes;BIGINT UNSIGNEDwith an integer literal isDECIMAL;TIMESTAMPwith a string literal is a string;CAST(bytes AS CHAR)can be NULL (Fuzz rustmy values against MySQL and fix six MySQL types #1581, Read MySQL ELT, EXPORT_SET and MAKE_SET numbers as numbers; SUBSTRING_INDEX of bytes #1585)driver = "asyncpg"typesjson/jsonbasstr,bit/varbitasasyncpg.BitString, geometric types asasyncpg.Pointand the like, ranges asasyncpg.Range[T]; a[tool.sqlty.types]entry for a SQL type now applies to every result value of that type, not only columns (Type PostgreSQL values as asyncpg loads them #1416)SELECT id FROM users AS u(a)is nowunknown-column(Rename columns by the alias list of a table, view or CTE #1495)sqlty checknow reads\N{name}escapes in query strings as Python does (Decode \N{name} escapes in query strings #1401)Go
Typed raw SQL for Go, checked in
go vetand golangci-lint with no generated code and no database (preview) (#1498).sqlty.SQL[R, P],NoParamsandNoRowsin the modulegithub.com/jirikuncar/sqlty/go;pgxqruns them through pgx v5 (All,One,Exec,Each,QueueAll,QueueOne,QueueExec)sqlty-vetapplies the SQL rules ofsqlty checkwith your[rules]severities, checks row struct fields aspgx.RowToStructByNamematches them, nullability, the Go types pgx scans, and the arguments ofpgxqcalls and of pgx'sQuery,QueryRow,ExecandBatch.Queuegivenstring(q). 74 µs per query in the analyzer, 100 ms for a package of 1,000 queriesjirikuncar/sqlty/go@vX.Y.Zrunsgo vetand annotates each findinggo/analysissuggested fixes:nullable-mismatchturns a field into a pointer,redundant-optionalremoves it, andunknown-columnandunknown-tablereplace the name in the query literal. A field changes only when nothing else can read it (Suggest fixes for Go diagnostics #1712)brew install jirikuncar/sqlty/sqlty-vetinstalls the tool alone; thesqltyformula ships onlysqlty(Ship sqlty-vet as its own Homebrew formula and release #1666)ESLint/TypeScript
sqlty/check-sqlaccepts a named row type:sql<User[]>is no longer reported as a mismatch, andeslint --fixno longer inlines the literal, whenUserhas exactly the row's shape (Accept a named row type in the ESLint plugin #1657)duplicate-columnis reported for every query. AfieldTransformthat maps two columns to one key is reported and gets no row type (Report duplicate output column names #1529)@sqlty/wasmanswers one bare SQL query withop: "query": columns, parameters and diagnostics (Type one bare SQL query from @sqlty/wasm #1390)Drivers
sqlty checkchecks the parameters ofexecuteandexecutemanyon connections, cursors and pools fromrustmy.connect,rustmy.aio.connect,rustmy.Poolandaio.create_pool, withparam-count-mismatch,param-type-mismatchandextra-param(Check the parameters of rustmy calls #1484).sqlty.drivers.rustmy(extrasqlty[rustmy]) has typedexecute,execute_async,scalarandscalar_async, blocking and async (Type rustmy rows with sqlty.drivers.rustmy #1485); example projectexamples/09_rustmy(Add a rustmy example project #1486).acquire()on an asyncpg pool is followed (Check the parameters of rustmy calls #1484)conn: Connection[tuple[object, ...]],AsyncConnection[...],Cursor[...]and aliases of them, are checked (Check driver calls on a subscripted connection annotation #1506)Checks
$1used more than once takes the type of its first typed use in every dialect (Type repeated parameters and report the ones PostgreSQL rejects #1557)argument-count-mismatch(Show SQLite function signatures #1558)unknown-tablesuggests the closest table, view or CTE, andcheck --fixreplaces the name (Suggest the table a misspelled name meant #1414);unknown-columnin an unaliased subquery says "in the subquery" (Name an unaliased subquery in the unknown-column message #1400)ambiguous-columnandduplicate-aliaspoint at related locations: theFROMitems that have the column and the earlier use of the alias (Point ambiguous-column and duplicate-alias at related locations #1404)CREATE EXTENSION: hstore (Type hstore once the schema creates the extension #1429), pg_trgm, fuzzystrmatch and pgcrypto (Type pg_trgm, fuzzystrmatch and pgcrypto functions #1430), ltree and intarray (Type ltree and intarray functions #1432), pgvectorvector,halfvecandsparsevecwith distances (Type pgvector functions and distances #1435)WITH; PostgreSQL, MySQL and DuckDB still report it (Let a SQLite CTE read a later CTE of its WITH #1500)CHECKconstraints are tracked by name, soALTER TABLE ... DROP CONSTRAINTclears only the values and discriminators of the constraint it names (Track CHECK constraints by name so DROP CONSTRAINT is precise #1684)LIKEcolumns ofCREATE TABLEstand where theLIKEis written (Place the columns a LIKE copies where it stands in the column list #1397)), as in(id + 1)*2and(id, name)=(1, 'a'), parses (Parse an operator right after)on PostgreSQL #1619)?placeholders keep their spans, socheckunderlines the name and--fixcan write (Keep diagnostic spans for queries with ? placeholders #1686)SELECT '%s'no longer types asLiteral['$0']; a%sinside a string literal or comment is left unbound (Leave a %s inside a string literal unbound #1714)dataclassdecorators,tuple[T, ...]as a variable-length tuple,Literal[-1], andfrom typing import *(Read nested format specs, aliased dataclasses, tuple[T, ...], Literal[-1] and typing star imports #1631)**glob stops at a linked directory it is already inside, instead of walking links to 64 levels, and no longer drops files of trees deeper than 64 levels (Stop schema glob walks at linked directories they are already inside #1699)-- sqlty: ignore[rulewithout]is a bare ignore at any line ending (End a SQL ignore's rule list at any line ending #1669)fetch_all(...), is read in NFKC form as Python reads it, so its query is checked (Find helper calls spelled with compatibility characters #1721)Editor and language server
FROM(Complete table functions in FROM #1437)ORDER BYandGROUP BYaliases and positions (Complete and hover ORDER BY and GROUP BY aliases and positions #1531)CHECKvalues inside string literals compared with or written to the column (Complete enum and CHECK values inside string literals #1541)FROM(Complete columns of every table before the query has a FROM #1439);FROMlists the relations that have the selected columns first (Complete FROM with the tables that have the selected columns first #1440); column names match as a subsequence, souidfindsuser_id(Match column completion by subsequence, not only prefix #1442)COMMENT ONin hover and completion, PostgreSQL and DuckDB (Show schema comments in hover and completion #1421)signatureHelp.enable = falseturns it off (Show the signatures of PostgreSQL built-ins in query calls #1425, Show signature help in the server, the playground and VS Code #1426, Show the signatures of DuckDB built-ins #1427, Show the signatures of MySQL built-ins #1428, Show SQLite function signatures #1558)ORDER BYandGROUP BYaliases and positions to the select item (Go to definition of output columns #1423)--sqlin TypeScript, JavaScript, Rust and Go files; highlighting only (Highlight--sqlstrings in TypeScript, JavaScript, Rust and Go #1723).sqlquery files (Serve semantic tokens for a range and for .sql query files #1456)completionList.itemDefaultswitheditRange, such as VS Code, gets the edit range once per list. Server CPU for a completion of a table name with 400 tables and 200 items: 1653 to 1107 µs (Send completion lists with one edit range and compact item data #1630)Playground
sqltemplates of the TypeScript example (Complete, hover and signature help in the playground's TypeScript templates #1587)CLI
sqlty checkreads each walked directory's configuration once, and a file no override matches shares its settings (Route each file's settings once per matched override set #1384, Read each directory's configuration once per walked directory #1637).agents/skills/, whereuvx library-skills --claudeandnpx library-skillsfind them (Ship the Agent Skills in the PyPI and npm packages #1457)Performance
ciproject at 4x it falls 14 % (Parse schemas and prepare modules in parallel #1358)check: about 3 % of wall time on a large project, 891 to 851 ms for the PyPI command (Skip freeing the workspace when the executable exits after check #1636, Skip freeing the workspace when the Python command exits after check #1716)WHENs on distinct columns check in 30 ms instead of 1 s and hover in 86 ms instead of 3.1 s (Keep editor and check work linear in query size #1548)FROMcompletion ranking: 5,000 tables 32.2 to 26.4 µs (Rank FROM completions on the relations the prefix already found #1579)Docs
Contributors
Thanks to @Kludex for
CHAR(n)parameters andCHECKvalues,SELECT *overJOIN USING, spans for?placeholders,DROP CONSTRAINTby name, fan-out keys throughWITH, symlink loops in schema globs, the ESLint named row type, theSUBSTRINGspan, the completion limit, Pydantic field types in JSON columns, NFKC helper names and--sqlhighlighting in other languages.Full changelog: v0.9.0...v0.10.0
This discussion was created from the release v0.10.0.
All reactions