Skip to content

Releases: sqlc-dev/sqlc

v1.21.0

06 Sep 18:51
63b5f90

Choose a tag to compare

What's new

MySQL engine improvements

sqlc previously didn't know how to parse a CALL statement when using the MySQL engine,
which meant it was impossible to use sqlc with stored procedures in MySQL databases.

Additionally, sqlc now supports IS [NOT] NULL in queries. And LIMIT and OFFSET clauses
now work with UNION.

SQLite engine improvements

GitHub user @orisano continues to bring bugfixes and
improvements to sqlc's SQLite engine. See the "Changes" section below for the
full list.

Plugin access to environment variables

If you're authoring a sqlc plugin, you can now configure
sqlc to pass your plugin the values of specific environment variables.

For example, if your plugin
needs the PATH environment variable, add PATH to the env list in the
plugins collection.

version: '2'
sql:
- schema: schema.sql
  queries: query.sql
  engine: postgresql
  codegen:
  - out: gen
    plugin: test
plugins:
- name: test
  env:
  - PATH
  wasm:
    url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm
    sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790

A variable named SQLC_VERSION is always included in the plugin's
environment, set to the version of the sqlc executable invoking it.

What's Changed

  • feat(endtoend/testdata): added two sqlite CAST tests and rearranged postgres tests for same by @andrewmbenton in #2551
  • build(deps): Bump wasmtime from v8.0.0 to v11.0.0 by @kyleconroy in #2553
  • feat(docs): add a reference to type overriding in datatypes.md by @andrewmbenton in #2557
  • docs: Update Docker installation instructions by @kyleconroy in #2552
  • docs: Modify config file version of mysql tutorial by @ken2403 in #2555
  • myriad formatting changes by @verygoodsoftwarenotvirus in #2558
  • build(deps): bump golang from 1.20.6 to 1.20.7 by @dependabot in #2563
  • build(deps): bump chardet from 5.1.0 to 5.2.0 in /docs by @dependabot in #2562
  • fix(engine/sqlite): support quoted identifier by @orisano in #2556
  • feat(engine/sqlite): support COLLATE for sqlite WHERE clause by @orisano in #2554
  • fix(engine/sqlite): fix compile error by @orisano in #2564
  • fix(engine/sqlite): fixed detection of column alias without AS by @orisano in #2560
  • fix(ci): bump go version for govulncheck in ci.yml by @andrewmbenton in #2568
  • fix: remove references to deprecated --experimental flag by @andrewmbenton in #2567
  • fix(postgres): Fixed a problem with array dimensions disappearing when using "ALTER TABLE ADD COLUMN" by @orisano in #2572
  • fix: remove GitHub sponsor integration by @andrewmbenton in #2574
  • fix(docs): improve discussion of prepared statements support by @andrewmbenton in #2604
  • build(deps): bump github.com/pganalyze/pg_query_go/v4 from 4.2.1 to 4.2.3 by @dependabot in #2583
  • docs: Reword phrase about pgx and multidimensional arrays by @rollulus in #2619
  • Gitignore Vim swap files by @Jille in #2616
  • build(deps): bump golang from 1.20.7 to 1.21.0 by @dependabot in #2596
  • build(deps): bump github.com/jackc/pgx/v5 from 5.4.2 to 5.4.3 by @dependabot in #2582
  • build(deps): bump pygments from 2.15.1 to 2.16.1 in /docs by @dependabot in #2584
  • build(deps): bump sphinxcontrib-applehelp from 1.0.4 to 1.0.7 in /docs by @dependabot in #2620
  • build(deps): bump sphinxcontrib-qthelp from 1.0.3 to 1.0.6 in /docs by @dependabot in #2622
  • build(deps): bump github.com/google/cel-go from 0.17.1 to 0.17.6 by @dependabot in #2650
  • fix Go struct tag parsing by @josharian in #2606
  • build(deps): bump sphinxcontrib-serializinghtml from 1.1.5 to 1.1.9 in /docs by @dependabot in #2641
  • build: Upgrade from Go 1.20 to Go 1.21 by @kyleconroy in #2665
  • refactor(astutils): remove redundant nil check in Walk by @Juneezee in #2660
  • build(deps): bump sphinxcontrib-devhelp from 1.0.2 to 1.0.5 in /docs by @dependabot in #2621
  • build(deps): Bump github.com/bytecodealliance/wasmtime-go from v11.0.0 to v12.0.0 by @kyleconroy in #2666
  • fix(compiler): Fix to not scan children under ast.RangeSubselect when retrieving table listing by @orisano in #2573
  • feat(mysql): Add parser support for IS [NOT] NULL by @Jille in #2651
  • fix(engine/sqlite): support NOT IN by @orisano in #2587
  • fix(codegen/golang): Fixed detection of the used package by @orisano in #2597
  • fix(engine/dolphin): Fixed problem that LIMIT OFFSET cannot be used with UNION ALL by @orisano in #2613
  • fix(compiler): support identifiers with schema by @orisano in #2579
  • fix(compiler): Fix column expansion to work with quoted non-keyword identifiers by @orisano in #2576
  • feat(engine/dolphin): support CALL statement by @orisano in #2614
  • fix(codegen): Compare define type in codegen by @tychy in #2578
  • build(deps): bump sphinx-rtd-theme from 1.2.2 to 1.3.0 in /docs by @dependabot in #2670
  • build(deps): bump sphinxcontrib-htmlhelp from 2.0.1 to 2.0.4 in /docs by @dependabot in #2671
  • feat(codegen): Allow plugins to access environment variables by @kyleconroy in #2669
  • fix(engine/sqlite): Fix ast when using compound operator by @orisano in #2673
  • fix(engine/sqlite): Fix to handle join clauses correctly by @orisano in #2674
  • fix(codegen): use correct Go types for bit strings and cid/oid/tid/xid with pgx/v4 by @andrewmbenton in #2668
  • build(deps): bump github.com/google/cel-go from 0.17.6 to 0.18.0 by @dependabot in #2691
  • docs: Missing emit_pointers_for_null_types configuration option in version 2 (#2682) by @topazur in #2683
  • fix(endtoend): Ensure all SQL works against PostgreSQL by @kyleconroy in #2684
  • build(deps): bump actions/checkout from 3 to 4 by @dependabot in #2694
  • build(deps): bump pytz from 2023.3 to 2023.3.post1 in /docs by @dependabot in #2695
  • chore: fix typo by @remyleone in #2696
  • chore: fix typo by @remyleone in #2697
  • docs: Document sqlc.* macros by @kyleconroy in #2698
  • docs(mysql): Document parseTime=true requirement by @kyleconroy in #2699
  • docs: add atlas to the list of supported migration frameworks by @andrewmbenton in #2700
  • docs: minor updates to insert howto by @andrewmbenton in #2701
  • build(devenv): bump go from 1.20.7 to 1.21.0 by @kyleconroy in #2702
  • feat(config): Add JSON schema files for configs by @kyleconroy in #2703
  • feat(cmd/sqlc): Bump version to 1.21.0 by @andrewmbenton in #2704
  • cmd/sqlc: Bump version to v1.21.0 by @kyleconroy in #2705

New Contributors

Full Changelog: v1.20.0...v1.21.0

v1.20.0

31 Jul 19:52
98ef71d

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v1.19.1...v1.20.0

v1.19.1

13 Jul 18:45
d9422dc

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v1.19.0...v1.19.1

v1.19.0

06 Jul 18:12
b643642

Choose a tag to compare

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

Read more

v1.18.0

27 Apr 17:51
e4b1c18

Choose a tag to compare

What's New

Remote code generation

Developed by @andrewmbenton

At its core, sqlc is powered by SQL engines, which include parsers, formatters,
analyzers and more. While our goal is to support each engine on each operating
system, it's not always possible. For example, the PostgreSQL engine does not
work on Windows.

To bridge that gap, we're announcing remote code generation, currently in
private alpha. To join the private alpha, sign up for the waitlist.

To configure remote generation, configure a cloud block in sqlc.json.

{
  "version": "2",
  "cloud": {
    "organization": "<org-id>",
    "project": "<project-id>",
  },
  ...
}

You'll also need to the SQLC_AUTH_TOKEN environment variable.

export SQLC_AUTH_TOKEN=<token>

When the cloud configuration exists, sqlc generate will default to remote
generation. If you'd like to generate code locally, pass the --no-remote
option.

sqlc generate --no-remote

Remote generation is off by default and requires an opt-in to use.

sqlc.embed

Developed by @nickjackson

Embedding allows you to reuse existing model structs in more queries, resulting
in less manual serilization work. First, imagine we have the following schema
with students and test scores.

CREATE TABLE students (
  id   bigserial PRIMARY KEY,
  name text,
  age  integer
)

CREATE TABLE test_scores (
  student_id bigint,
  score integer,
  grade text
)

We want to select the student record and the highest score they got on a test.
Here's how we'd usually do that:

-- name: HighScore :many
WITH high_scores AS (
  SELECT student_id, max(score) as high_score
  FROM test_scores
  GROUP BY 1
)
SELECT students.*, high_score::integer
FROM students
JOIN high_scores ON high_scores.student_id = students.id;

When using Go, sqlc will produce a struct like this:

type HighScoreRow struct {
	ID        int64
	Name      sql.NullString
	Age       sql.NullInt32
	HighScore int32
}

With embedding, the struct will contain a model for the table instead of a
flattened list of columns.

-- name: HighScoreEmbed :many
WITH high_scores AS (
  SELECT student_id, max(score) as high_score
  FROM test_scores
  GROUP BY 1
)
SELECT sqlc.embed(students), high_score::integer
FROM students
JOIN high_scores ON high_scores.student_id = students.id;
type HighScoreRow struct {
	Student   Student
	HighScore int32
}

sqlc.slice

Developed by Paul Cameron and Jille Timmermans

The MySQL Go driver does not support passing slices to the IN operator. The
sqlc.slice function generates a dynamic query at runtime with the correct
number of parameters.

/* name: SelectStudents :many */
SELECT * FROM students 
WHERE age IN (sqlc.slice("ages"))
func (q *Queries) SelectStudents(ctx context.Context, arges []int32) ([]Student, error) {

This feature is only supported in MySQL and cannot be used with prepared
queries.

Batch operation improvements

When using batches with pgx, the error returned when a batch is closed is
exported by the generated package. This change allows for cleaner error
handling using errors.Is.

errors.Is(err, generated_package.ErrBatchAlreadyClosed)

Previously, you would have had to check match on the error message itself.

err.Error() == "batch already closed"

The generated code for batch operations always lived in batch.go. This file
name can now be configured via the output_batch_file_name configuration
option.

Configurable query parameter limits for Go

By default, sqlc will limit Go functions to a single parameter. If a query
includes more than one parameter, the generated method will use an argument
struct instead of positional arguments. This behavior can now be changed via
the query_parameter_limit configuration option. If set to 0, every
generated method will use a argument struct.

What's Changed

Read more

v1.17.2

22 Feb 18:02
140db73

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v1.17.0...v1.17.1

v1.17.1

22 Feb 17:18
fc6ed52

Choose a tag to compare

v1.17.1 Pre-release
Pre-release

Note

This release contained a build failure for Windows and will not be released. Please see v1.17.2

What's Changed

New Contributors

Full Changelog: v1.17.0...v1.17.1

v1.17.0

14 Feb 07:14
fa985d0

Choose a tag to compare

## What's Changed

New Contributors

Full Changelog: v1.16.0...v1.17.0

v1.16.0

09 Nov 04:41
89922d4

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v1.15.0...v1.16.0

v1.15.0

07 Aug 18:14
61f1758

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v1.14.0...v1.15.0