v1.19.0
Released 2023-07-06 · View on GitHub
Release notes
sqlc vet
sqlc vet runs queries through a set of lint rules.
Rules are defined in the sqlc configuration file. They consist
of a name, message, and a Common Expression Language (CEL)
expression. Expressions are evaluated using cel-go.
If an expression evaluates to true, an error is reported using the given message.
While these examples are simplistic, they give you a flavor of the types of rules you can write.
version: 2
sql:
- schema: "query.sql"
queries: "query.sql"
engine: "postgresql"
gen:
go:
package: "authors"
out: "db"
rules:
- no-pg
- no-delete
- only-one-param
- no-exec
rules:
- name: no-pg
message: "invalid engine: postgresql"
rule: |
config.engine == "postgresql"
- name: no-delete
message: "don't use delete statements"
rule: |
query.sql.contains("DELETE")
- name: only-one-param
message: "too many parameters"
rule: |
query.params.size() > 1
- name: no-exec
message: "don't use exec"
rule: |
query.cmd == "exec"Database connectivity
vet also marks the first time that sqlc can connect to a live, running
database server. We'll expand this functionality over time, but for now it
powers the sqlc/db-prepare built-in rule.
When a database is configured, the
sqlc/db-preapre rule will attempt to prepare each of your
queries against the connected database and report any failures.
version: 2
sql:
- schema: "query.sql"
queries: "query.sql"
engine: "postgresql"
gen:
go:
package: "authors"
out: "db"
database:
uri: "postgresql://postgres:password@localhost:5432/postgres"
rules:
- sqlc/db-prepareTo see this in action, check out the authors example.
Please note that sqlc does not manage or migrate your database. Use your
migration tool of choice to create the necessary database tables and objects
before running sqlc vet.
Omit unused structs
Added a new configuration parameter omit_unused_structs which, when set to
true, filters out table and enum structs that aren't used in queries for a given
package.
Suggested CI/CD setup
With the addition of sqlc diff and sqlc vet, we encourage users to run sqlc
in your CI/CD pipelines. See our suggested CI/CD setup for
more information.
Simplified plugin development
The sqlc-gen-kotlin and sqlc-gen-python plugins have been updated use the upcoming WASI support in Go 1.21. Building these plugins no longer requires TinyGo.
Changes
Bug Fixes
- Pointers overrides skip imports in generated query files (#2240)
- CASE-ELSE clause is not properly parsed when a value is constant (#2238)
- Fix toSnakeCase to handle input in CamelCase format (#2245)
- Add location info to sqlite ast (#2298)
- Add override tags to result struct (#1867) (#1887)
- Override types of aliased columns and named parameters (#1884)
- Resolve duplicate fields generated when inheriting multiple tables (#2089)
- Check column references in ORDER BY (#1411) (#1915)
- MySQL slice shadowing database/sql import (#2332)
- Don't defer rows.Close() if pgx.BatchResults.Query() failed (#2362)
- Fix type overrides not working with sqlc.slice (#2351)
- Type overrides on columns for parameters inside an IN clause (#2352)
- Broken interaction between query_parameter_limit and pq.Array() (#2383)
- (codegen/golang) Bring :execlastid in line with the rest (#2378)
Documentation
- Update changelog.md with some minor edits (#2235)
- Add F# community plugin (#2295)
- Add a ReadTheDocs config file (#2327)
- Update query_parameter_limit documentation (#2374)
- Add launch announcement banner
Features
- PostgreSQL capture correct line and column numbers for parse error (#2289)
- Add supporting COMMENT ON VIEW (#2249)
- To allow spaces between function name and arguments of functions to be rewritten (#2250)
- Add support for pgx/v5 emit_pointers_for_null_types flag (#2269)
- (mysql) Support unsigned integers (#1746)
- Allow use of table and column aliases for table functions returning unknown types (#2156)
- Support "LIMIT ?" in UPDATE and DELETE for MySQL (#2365)
- (internal/codegen/golang) Omit unused structs from output (#2369)
- Improve default names for BETWEEN ? AND ? to have prefixes from_ and to_ (#2366)
- (cmd/sqlc) Add the vet subcommand (#2344)
- (sqlite) Add support for UPDATE/DELETE with a LIMIT clause (#2384)
- Add support for BETWEEN sqlc.arg(min) AND sqlc.arg(max) (#2373)
- (cmd/vet) Prepare queries against a database (#2387)
- (cmd/vet) Prepare queries for MySQL (#2388)
- (cmd/vet) Prepare SQLite queries (#2389)
- (cmd/vet) Simplify environment variable substiution (#2393)
- (cmd/vet) Add built-in db-prepare rule
- Add compiler support for NOTIFY and LISTEN (PostgreSQL) (#2363)
Miscellaneous Tasks
- A few small staticcheck fixes (#2361)
- Remove a bunch of dead code (#2360)
- (scripts/regenerate) Should also update stderr.txt (#2379)
Build
- (deps) Bump requests from 2.25.1 to 2.31.0 in /docs (#2283)
- (deps) Bump golang from 1.20.3 to 1.20.4 (#2256)
- (deps) Bump google.golang.org/grpc from 1.54.0 to 1.55.0 (#2265)
- (deps) Bump github.com/mattn/go-sqlite3 from 1.14.16 to 1.14.17 (#2293)
- (deps) Bump golang.org/x/sync from 0.1.0 to 0.2.0 (#2266)
- (deps) Bump golang from 1.20.4 to 1.20.5 (#2301)
- Configure dependencies via devenv.sh (#2319)
- Configure dependencies via devenv.sh (#2326)
- (deps) Bump golang.org/x/sync from 0.2.0 to 0.3.0 (#2328)
- (deps) Bump google.golang.org/grpc from 1.55.0 to 1.56.0 (#2333)
- (deps) Bump google.golang.org/protobuf from 1.30.0 to 1.31.0 (#2370)
- (deps) Bump actions/checkout from 2 to 3 (#2357)
- Run govulncheck on all builds (#2372)
- (deps) Bump google.golang.org/grpc from 1.56.0 to 1.56.1 (#2358)
Cmd/sqlc
- Show helpful output on missing subcommand (#2345)
Codegen
- Use catalog's default schema (#2310)
- (go) Add tests for tables with dashes (#2312)
- (go) Strip invalid characters from table and column names (#2314)
- (go) Support JSON tags for nullable enum structs (#2121)
Internal/config
- Support golang overrides for slices (#2339)
Kotlin
- Use latest version of sqlc-gen-kotlin (#2356)
Postgres
- Column merging for table inheritence (#2315)
Protos
- Add missing field name (#2354)
Python
- Use latest version of sqlc-gen-python (#2355)
Remote
- Use user-id/password auth (#2262)
Sqlite
- Fixed sqlite column type override (#1986)