-
Notifications
You must be signed in to change notification settings - Fork 923
v1.18.0 #2234
-
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
- Upgrade to Go 1.20 by @kyleconroy in Upgrade to Go 1.20 #2105
- test: Skip tests if required plugins are missing by @kyleconroy in test: Skip tests if required plugins are missing #2104
- fix: Prevent variable redeclaration in single param conflict for pgx by @zaneli in fix: Prevent variable redeclaration in single param conflict for pgx #2058
- fix: Retrieve Larg/Rarg join query after inner join by @zaneli in fix: Retrieve Larg/Rarg join query after inner join #2051
- fix: Rename argument when conflicted to imported package by @zaneli in fix: Rename argument when conflicted to imported package #2048
- fix: pgx closed batch return pointer if need To check if batch is closed if you need to return a pointer to the type the wrong code is generated #1959 by @flymedllva in fix: pgx closed batch return pointer if need #1959 #1960
- parser: Generate correct types for
SELECT NOT EXISTS
by @haines in parser: Generate correct types forSELECT NOT EXISTS
#1972 - Implement ALTER TYPE SET SCHEMA by @linux2647 in Implement ALTER TYPE SET SCHEMA #2027
- Fix test: Bump version to v1.17.2 in internal/endtoend/testdata/ddl_alter_type_set_schema/postgresql by @monkey-mas in Fix test: Bump version to v1.17.2 in internal/endtoend/testdata/ddl_alter_type_set_schema/postgresql #2108
- build(deps): bump github.com/antlr/antlr4/runtime/Go/antlr from 0.0.0-20220626175859-9abda183db8e to 1.4.10 by @dependabot in build(deps): bump github.com/antlr/antlr4/runtime/Go/antlr from 0.0.0-20220626175859-9abda183db8e to 1.4.10 #2109
- Implement support for enum ordering by @mikemherron in Implement support for enum ordering #2111
- engine/postgres: Upgrade to pg_query_go/v4 by @kyleconroy in engine/postgres: Upgrade to pg_query_go/v4 #2114
- build(deps): bump github.com/jackc/pgx/v4 from 4.18.0 to 4.18.1 by @dependabot in build(deps): bump github.com/jackc/pgx/v4 from 4.18.0 to 4.18.1 #2119
- Enum ordering minor code tidy up by @mikemherron in Enum ordering minor code tidy up #2126
- build(deps): bump golang from 1.20.1 to 1.20.2 by @dependabot in build(deps): bump golang from 1.20.1 to 1.20.2 #2135
- build(deps): bump google.golang.org/protobuf from 1.28.1 to 1.29.0 by @dependabot in build(deps): bump google.golang.org/protobuf from 1.28.1 to 1.29.0 #2137
- allow deleting composite types by @josharian in allow deleting composite types #2138
- Fix typo (incorrect domain in URL) by @starquake in Fix typo (incorrect domain in URL) #2142
- build(deps): bump google.golang.org/protobuf from 1.29.0 to 1.29.1 by @dependabot in build(deps): bump google.golang.org/protobuf from 1.29.0 to 1.29.1 #2143
- docs(config.md): add
sqlite
as engine option by @aaanders in docs(config.md): addsqlite
as engine option #2164 - Add link to introductory blog post by @meblum in Add link to introductory blog post #2155
- cmd/sqlc: Remove --experimental flag by @kyleconroy in cmd/sqlc: Remove --experimental flag #2170
- docs: Add first pass at pgx documentation by @kyleconroy in docs: Add first pass at pgx documentation #2174
- sqlite: Add support for CREATE TABLE ... STRICT by @kyleconroy in sqlite: Add support for CREATE TABLE ... STRICT #2175
- cmd/sqlc: Add option to disable process-based plugins by @kyleconroy in cmd/sqlc: Add option to disable process-based plugins #2180
- codegen: Correctly generate CopyFrom columns for single-column copyfroms by @Jille in codegen: Correctly generate CopyFrom columns for single-column copyfroms #2185
- More consistent filename formatting in codegen stderr output by @andrewmbenton in More consistent filename formatting in codegen stderr output #2186
- docs: Add missed configuration option by @abekoh in docs: Add missed configuration option #2188
- bin/sqlc: Add SQLCTMPDIR environment variable by @kyleconroy in bin/sqlc: Add SQLCTMPDIR environment variable #2189
- fix: correct singularization of "waves" by @rliebz in fix: correct singularization of "waves" #2194
- Add sqlc.slice() to support IN clauses in MySQL (Support passing slices to MySQL queries #695 ) by @Jille in Add sqlc.slice() to support IN clauses in MySQL (#695) #1816
- feat: add
sqlc.embed
to allow model re-use by @nickjackson in feat: addsqlc.embed
to allow model re-use #1615 - feat(Go):Add query_parameter_limit conf to codegen by @go-mez in feat(Go):Add query_parameter_limit conf to codegen #1558
- fix: Honor Package level renames in v2 yaml config by @Emyrk in fix: Honor Package level renames in v2 yaml config #2001
- tests: Add tests for reanme fix in v2 by @kyleconroy in tests: Add tests for reanme fix in v2 #2196
- build(deps): bump golang from 1.20.2 to 1.20.3 by @dependabot in build(deps): bump golang from 1.20.2 to 1.20.3 #2192
- build(deps): bump actions/setup-go from 3 to 4 by @dependabot in build(deps): bump actions/setup-go from 3 to 4 #2150
- build(deps): bump google.golang.org/protobuf from 1.29.1 to 1.30.0 by @dependabot in build(deps): bump google.golang.org/protobuf from 1.29.1 to 1.30.0 #2151
- build(deps): bump github.com/spf13/cobra from 1.6.1 to 1.7.0 by @dependabot in build(deps): bump github.com/spf13/cobra from 1.6.1 to 1.7.0 #2193
- fix:
specifies parameter ":one" without containing a RETURNING clause
by @ihatov08 in fix:specifies parameter ":one" without containing a RETURNING clause
#2173 - Customizable batch output file name (add OutputBatchFileName field) by @JordanP in Customizable batch output file name (add OutputBatchFileName field) #2178
- fix: update panic panic: expected range var #1590 by @nusr in fix: update panic #1590 #2154
- Define base error in batch.go for better error handling by @Aisoipheo in Define base error in batch.go for better error handling #2147
- fix: mysql delete join panic by @nusr in fix: mysql delete join panic #2197
- config: Add top-level cloud configuration by @kyleconroy in config: Add top-level cloud configuration #2204
- Use os.CreateTemp() to remove ioutil dependency by @andrewmbenton in Use os.CreateTemp() to remove ioutil dependency #2216
- Avoid some unnecessary buffering when reading config file by @andrewmbenton in Avoid some unnecessary buffering when reading config file #2215
- Add remote execution for codegen by @andrewmbenton in Add remote execution for codegen #2214
- fix panic caused by invalid shorthand for
--no-remote
flag by @andrewmbenton in fix panic caused by invalid shorthand for--no-remote
flag #2218 - build(deps): bump github.com/lib/pq from 1.10.7 to 1.10.8 by @dependabot in build(deps): bump github.com/lib/pq from 1.10.7 to 1.10.8 #2211
- wasm: Upgrade to wasmtime v8.0.0 by @kyleconroy in wasm: Upgrade to wasmtime v8.0.0 #2222
- Allow sql_package: "go-sql-driver/mysql" by @Jille in Allow sql_package: "go-sql-driver/mysql" #2219
- ext/wasm: Check exit code on returned error by @kyleconroy in ext/wasm: Check exit code on returned error #2223
- Update default remote execution hostname by @andrewmbenton in Update default remote execution hostname #2230
- fix: missing import with pointer overrides, solves When using type overrides with pointer true import are missing #2168 Column override with imported go-type invalid when pointer:true #2125 by @ludusrusso in fix: missing import with pointer overrides, solves #2168 #2125 #2217
- build(deps): bump github.com/lib/pq from 1.10.8 to 1.10.9 by @dependabot in build(deps): bump github.com/lib/pq from 1.10.8 to 1.10.9 #2229
- Add support for SHOW WARNINGS and SELECTs without a FROM by @Jille in Add support for SHOW WARNINGS and SELECTs without a FROM #2227
- build(deps): bump github.com/go-sql-driver/mysql from 1.7.0 to 1.7.1 by @dependabot in build(deps): bump github.com/go-sql-driver/mysql from 1.7.0 to 1.7.1 #2228
- Add changelog for v1.18.0 by @kyleconroy in Add changelog for v1.18.0 #2231
- test: Remove remote test by @kyleconroy in test: Remove remote test #2232
- cmd/sqlc: Bump version to 1.18.0 by @kyleconroy in cmd/sqlc: Bump version to 1.18.0 #2233
New Contributors
- @flymedllva made their first contribution in fix: pgx closed batch return pointer if need #1959 #1960
- @haines made their first contribution in parser: Generate correct types for
SELECT NOT EXISTS
#1972 - @linux2647 made their first contribution in Implement ALTER TYPE SET SCHEMA #2027
- @monkey-mas made their first contribution in Fix test: Bump version to v1.17.2 in internal/endtoend/testdata/ddl_alter_type_set_schema/postgresql #2108
- @mikemherron made their first contribution in Implement support for enum ordering #2111
- @starquake made their first contribution in Fix typo (incorrect domain in URL) #2142
- @aaanders made their first contribution in docs(config.md): add
sqlite
as engine option #2164 - @meblum made their first contribution in Add link to introductory blog post #2155
- @abekoh made their first contribution in docs: Add missed configuration option #2188
- @go-mez made their first contribution in feat(Go):Add query_parameter_limit conf to codegen #1558
- @Emyrk made their first contribution in fix: Honor Package level renames in v2 yaml config #2001
- @ihatov08 made their first contribution in fix:
specifies parameter ":one" without containing a RETURNING clause
#2173 - @JordanP made their first contribution in Customizable batch output file name (add OutputBatchFileName field) #2178
- @nusr made their first contribution in fix: update panic #1590 #2154
- @Aisoipheo made their first contribution in Define base error in batch.go for better error handling #2147
Full Changelog: v1.17.2...v1.18.0
This discussion was created from the release v1.18.0.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 3 -
🎉 6 -
🚀 5