release notes — July 6, 2023

sqlc v1.19.0 released

Version 1.19.0

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-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.

Changelog

Full list of changes here.

< All posts