Skip to content

SQLTy vs scany and sqlx

scany and jmoiron/sqlx scan rows into your structs at runtime. A missing or misnamed column is an error when the query runs. SQLTy checks the same structs against the query in go vet, before the code runs. They complement each other: SQLTy checks, the scanner runs.

Quick comparison

scany 2.1 / sqlx 1.4 SQLTy for Go (preview)
When a mismatch shows At runtime ("missing destination name") In go vet
Drivers database/sql and pgx (scany); database/sql (sqlx) pgx v5 through pgxq and direct pgx calls
Named parameters sqlx :name Not yet
IN lists sqlx.In = ANY($1)
Nested structs scany: nested and prefixed Embedded by value, as pgx

Where SQLTy is stronger

  • Mismatches are caught statically, with no test needed for each query.
  • Types and nullability are checked, not only names.

Where scany and sqlx are stronger

  • database/sql and any database.
  • Named parameters, In expansion and nested structs.

Which should you choose?

Keep scany or sqlx if you are on database/sql. On pgx v5, pgxq scans rows into the same structs that SQLTy checks.

What SQLTy is missing

  • Checks of scany and sqlx calls, database/sql, named parameters, MySQL and SQLite.

Common questions

Does SQLTy check scany or sqlx calls?

Not yet. It checks queries run through pgxq or pgx's own Query, QueryRow, Exec and Batch.Queue.

Sources

  • scany 2.1.4 README and dbscan; jmoiron/sqlx 1.4.0 bind.go, named.go, sqlx.go