Skip to content

v2.0.0-rc.1

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 10 Sep 07:49
· 105 commits to main since this release

Changed

  • The checker is the product; the runtime is a library per database. The root module
    github.com/kr9ly/sqlshape/v2 now holds only the declarations (Query, One, Stmt, Render,
    the row-binding rules) and has no dependencies. Running a statement on pgx is the module
    github.com/kr9ly/sqlshape/postgres/v2: postgres.Run(ctx, db, stmt, p), Collect, First,
    Exec, Get / Find / ExecOne for One, and MatView, Copy, Batch, LoadUserTypes,
    ConstraintError, Violates, ErrNoRows moved there (the methods stmt.Run(ctx, db, p) are
    gone: a module cannot add methods to another's type). Labelled and UnknownLabelError stay in
    the root. pgtest is its own module. The PostgreSQL analyzer and migration tools are the module
    github.com/kr9ly/sqlshape/check/postgres/v2, the MySQL analyzer check/mysql (was mysql);
    both are tool-facing, imported by the binary and pgtest. An application's go.mod carries the
    root, its runtime and its own driver, nothing of the checker's.
  • The markers the checker recognizes are configurable: -query=pkg.Func,pkg.Other:one registers
    a program's own generic marker functions, read like Query / One. A program may run its
    statements through a runtime of its own; what only sqlshape's runtime promises (the rendered SQL
    is the checked SQL, violations come back under the expect line's names, One rejects a second
    row) is stated in docs/runtime.md.

Added

  • MySQL, a first slice. A schema.sql that declares -- sqlshape: mysql 8.4 is loaded by the
    MySQL schema loader and every Query is judged by the MySQL analyzer: the statement's own errors
    (unknown table or column, ambiguity, syntax, with MySQL's message and error number), result
    columns against R by name, type and nullability, parameters against P where their context
    types them (compared with or assigned to a column, LIMIT, the argument positions a function
    declares). Single-block SELECT, INSERT, UPDATE and DELETE over base tables. Expressions are typed
    by the server's own rules, read out of its source: arithmetic promotion (Item_num_op), CASE /
    IF / COALESCE / GREATEST through field_type_merge, casts, aggregates, and every function of
    the native registry through its Item class family and resolve_type facts, so a SUM is a
    nullable decimal, a comparison a bigint(1) a Go bool can carry, LENGTH(?) types its
    placeholder as a string. The rules are checked against a real mysqld (a local test, not a CI
    dependency): every registry function over representative argument types, 5,267 statements,
    agrees with the server on type and nullability but for 10. Subqueries (scalar, IN, EXISTS,
    ANY / ALL, correlated), derived tables (LATERAL too), views, common table expressions
    (recursive too), UNION / EXCEPT / INTERSECT and INSERT ... SELECT are analyzed with the
    server's rules for what they produce: a scalar subquery is NULL unless its query is guaranteed a
    row, a recursive CTE's columns are always nullable, a derived table the server materializes
    retypes a small integer expression to an int, a merged view is updatable. What has no rule yet
    (user variables, the temporal hybrids such as ADDTIME) is accepted with a note; One,
    MatView, Copy and the obligations are not supported yet. Parameters stay {{.X}} in the
    template; the analyzer speaks ? to MySQL.

Changed

  • The binary is its own Go module, github.com/kr9ly/sqlshape/cmd/sqlshape/v2, under the GNU
    General Public License v2; install it with go install github.com/kr9ly/sqlshape/cmd/sqlshape/v2@latest.
    Everything a checked program imports stays Apache 2.0. Every module's path carries the /v2
    major-version suffix Go requires of a 2.x module, so an import of 1.x is
    github.com/kr9ly/sqlshape and of 2.x github.com/kr9ly/sqlshape/v2. The modules of the
    repository release together under one version, tagged vX.Y.Z and <module>/vX.Y.Z on the
    same commit.