v1.19.0
What's new
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-prepare
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-prepare
To 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.
What's Changed
- Fixing Document Typo by @jyono in #2236
- Update changelog.md with some minor edits by @andrewmbenton in #2235
- fix: pointers overrides skip imports in generated query files by @ludusrusso in #2240
- fix: CASE-ELSE clause is not properly parsed when a value is constant by @nozaq in #2238
- remote: use user-id/password auth by @andrewmbenton in #2262
- Feat: PostgreSQL capture correct line and column numbers for parse error by @StevenACoffman in #2289
- build(deps): bump requests from 2.25.1 to 2.31.0 in /docs by @dependabot in #2283
- build(deps): bump golang from 1.20.3 to 1.20.4 by @dependabot in #2256
- build(deps): bump google.golang.org/grpc from 1.54.0 to 1.55.0 by @dependabot in #2265
- build(deps): bump github.com/mattn/go-sqlite3 from 1.14.16 to 1.14.17 by @dependabot in #2293
- build(deps): bump golang.org/x/sync from 0.1.0 to 0.2.0 by @dependabot in #2266
- docs: Add F# community plugin by @kyleconroy in #2295
- Update bufbuild plugin references by @mfridman in #2253
- engine/sqlite: Handle untyped sqlite columns without crashing by @andrewmbenton in #2281
- feat(sqlite) add support sqlc functions by @hakobera in #2274
- feat: add supporting COMMENT ON VIEW by @orisano in #2249
- feat: to allow spaces between function name and arguments of functions to be rewritten by @orisano in #2250
- fix: fix toSnakeCase to handle input in camel case format by @orisano in #2245
- feat: add support for pgx/v5 emit_pointers_for_null_types flag by @ludusrusso in #2269
- fix(engine/sqlite): add location info to sqlite ast by @orisano in #2298
- build(deps): bump golang from 1.20.4 to 1.20.5 by @dependabot in #2301
- sqlite: fixed sqlite column type override by @mcdoker18 in #1986
- Fix hyphen in go struct names by @kyleconroy in #2305
- codegen: Use catalog's default schema by @kyleconroy in #2310
- codegen(go): Add tests for tables with dashes by @kyleconroy in #2312
- Update BUG_REPORT.yml by @kyleconroy in #2313
- fix citext resolution issues by @ryan-berger in #1629
- fix: add override tags to result struct (#1867) by @akutschera in #1887
- fix: Override types of aliased columns and named parameters by @haines in #1884
- fix: resolve duplicate fields generated when inheriting multiple tables by @ethan-xiao in #2089
- postgres: Column merging for table inheritence by @kyleconroy in #2315
- codegen(go): Strip invalid characters from table and column names by @kyleconroy in #2314
- feat(mysql): handle unsigned integers by @roccoblues in #1746
- fix: check column references in ORDER BY (#1411) by @akutschera in #1915
- Update using-go-and-pgx.rst by @teenjuna in #2318
- Support JSON tags for nullable enum structs by @mikemherron in #2121
- build: Configure dependencies via devenv.sh by @kyleconroy in #2319
- feat: Allow use of table and column aliases for table functions returning unknown types by @haines in #2156
- build: Configure dependencies via devenv.sh by @kyleconroy in #2326
- docs: Add a ReadTheDocs config file by @kyleconroy in #2327
- build(deps): bump golang.org/x/sync from 0.2.0 to 0.3.0 by @dependabot in #2328
- build(deps): bump google.golang.org/grpc from 1.55.0 to 1.56.0 by @dependabot in #2333
- fix(sqlite) fix EXISTS operator by @hakobera in #2334
- improve init command to create v2/v1 yaml file by @dangquangdon in #2335
- Update changelog.md by @kyleconroy in #2342
- fix: MySQL slice shadowing database/sql import by @LudovicDebost in #2332
- internal/config: support golang overrides for slices by @andrewmbenton in #2339
- cmd/sqlc: Show helpful output on missing subcommand by @kyleconroy in #2345
- Support for parsing REFRESH MATERIALIZED VIEW by @Jille in #2347
- Add json_tags_id_camelcase configuration option by @jwc-clinnection in #2325
- protos: Add missing field name by @kyleconroy in #2354
- python: Use latest version of sqlc-gen-python by @kyleconroy in #2355
- kotlin: Use latest version of sqlc-gen-kotlin by @kyleconroy in #2356
- build(deps): bump google.golang.org/protobuf from 1.30.0 to 1.31.0 by @dependabot in #2370
- build(deps): bump actions/checkout from 2 to 3 by @dependabot in #2357
- build: Run govulncheck on all builds by @kyleconroy in #2372
- build(deps): bump google.golang.org/grpc from 1.56.0 to 1.56.1 by @dependabot in #2358
- A few small staticcheck fixes by @Jille in #2361
- Support "LIMIT ?" in UPDATE and DELETE for MySQL by @Jille in #2365
- Add compiler support for NOTIFY and LISTEN (PostgreSQL) by @Jille in #2363
- Don't defer rows.Close() if pgx.BatchResults.Query() failed by @Jille in #2362
- Remove a bunch of dead code by @Jille in #2360
- Fix type overrides not working with sqlc.slice by @Jille in #2351
- docs: Update query_parameter_limit documentation by @kyleconroy in #2374
- internal/codegen/golang: omit unused structs from output by @andrewmbenton in #2369
- Fix type overrides on columns for parameters inside an IN clause by @Jille in #2352
- Improve default names for BETWEEN ? AND ? to have prefixes from_ and to_ by @Jille in #2366
- cmd/sqlc: Add the vet subcommand by @kyleconroy in #2344
- sqlite: Add support for UPDATE/DELETE with a LIMIT clause by @Jille in #2384
- Fix broken interaction between query_parameter_limit and pq.Array() by @Jille in #2383
- Add support for BETWEEN sqlc.arg(min) AND sqlc.arg(max) by @Jille in #2373
- scripts/regenerate should also update stderr.txt by @Jille in #2379
- codegen/golang: Bring :execlastid in line with the rest by @Jille in #2378
- feat(cmd/vet): Prepare queries against a database by @kyleconroy in #2387
- feat(cmd/vet): Prepare queries for MySQL by @kyleconroy in #2388
- feat(cmd/vet): Prepare SQLite queries by @kyleconroy in #2389
- feat(cmd/vet): Simplify environment variable substiution by @kyleconroy in #2393
- feat(cmd/vet): Add built-in db-prepare rule by @kyleconroy in #2396
- docs: add a favicon by @andrewmbenton in #2397
- cmd/vet: Add --no-database option by @kyleconroy in #2405
- chore: remove refs to deprecated io/ioutil by @testwill in #2404
- config: Change database URL to URI by @kyleconroy in #2407
- docs: Add release notes for v1.19.0 by @kyleconroy in #2406
- docs: some v1.19.0 release copyediting by @andrewmbenton in #2409
- cmd/sqlc: Bump version to 1.19.0 by @kyleconroy in #2408
New Contributors
- @jyono made their first contribution in #2236
- @nozaq made their first contribution in #2238
- @StevenACoffman made their first contribution in #2289
- @mfridman made their first contribution in #2253
- @ethan-xiao made their first contribution in #2089
- @roccoblues made their first contribution in #1746
- @teenjuna made their first contribution in #2318
- @dangquangdon made their first contribution in #2335
- @LudovicDebost made their first contribution in #2332
- @jwc-clinnection made their first contribution in #2325
- @testwill made their first contribution in #2404
Full Changelog: v1.18.0...v1.19.0