Skip to content

Commit 98ef71d

Browse files
feat(cmd/sqlc): Bump version to 1.20.0 (#2549)
* feat(cmd/sqlc): Bump version to 1.20.0 --------- Co-authored-by: Andrew Benton <[email protected]>
1 parent a58e3a5 commit 98ef71d

File tree

2,401 files changed

+2639
-2402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,401 files changed

+2639
-2402
lines changed

.github/ISSUE_TEMPLATE/BUG_REPORT.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ body:
99
description: What version of sqlc are you running? If you don't know, run `sqlc version`.
1010
multiple: false
1111
options:
12+
- 1.20.0
1213
- 1.19.1
1314
- 1.19.0
1415
- 1.18.0

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Riza, Inc.'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '1.19.1'
25+
release = '1.20.0'
2626

2727

2828
# -- General configuration ---------------------------------------------------

docs/overview/install.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ docker run --rm -v "%cd%:/src" -w /src kjconroy/sqlc generate
4848

4949
## Downloads
5050

51-
Get pre-built binaries for *v1.19.1*:
51+
Get pre-built binaries for *v1.20.0*:
5252

53-
- [Linux](https://downloads.sqlc.dev/sqlc_1.19.1_linux_amd64.tar.gz)
54-
- [macOS](https://downloads.sqlc.dev/sqlc_1.19.1_darwin_amd64.zip)
55-
- [Windows](https://downloads.sqlc.dev/sqlc_1.19.1_windows_amd64.zip)
53+
- [Linux](https://downloads.sqlc.dev/sqlc_1.20.0_linux_amd64.tar.gz)
54+
- [macOS](https://downloads.sqlc.dev/sqlc_1.20.0_darwin_amd64.zip)
55+
- [Windows](https://downloads.sqlc.dev/sqlc_1.20.0_windows_amd64.zip)
5656

5757
See [downloads.sqlc.dev](https://downloads.sqlc.dev/) for older versions.

docs/reference/changelog.md

+236
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,242 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [1.20.0](https://github.com/sqlc-dev/sqlc/releases/tag/v1.20.0)
5+
Released 2023-07-31
6+
7+
### Release notes
8+
9+
#### `kyleconroy/sqlc` is now `sqlc-dev/sqlc`
10+
11+
We've completed our migration to the [sqlc-dev/sqlc](https://github.com/sqlc-dev/sqlc) repository. All existing links and installation instructions will continue to work. If you're using the `go` tool to install `sqlc`, you'll need to use the new import path to get v1.20.0 (and all future versions).
12+
13+
```sh
14+
# INCORRECT: old import path
15+
go install github.com/kyleconroy/sqlc/cmd/[email protected]
16+
17+
# CORRECT: new import path
18+
go install github.com/sqlc-dev/sqlc/cmd/[email protected]
19+
```
20+
21+
We designed the upgrade process to be as smooth as possible. If you run into any issues, please [file a bug report](https://github.com/sqlc-dev/sqlc/issues/new?assignees=&labels=bug%2Ctriage&projects=&template=BUG_REPORT.yml) via GitHub.
22+
23+
#### Use `EXPLAIN ...` output in lint rules
24+
25+
`sqlc vet` can now run `EXPLAIN` on your queries and include the results for use in your lint rules. For example, this rule checks that `SELECT` queries use an index.
26+
27+
```yaml
28+
version: 2
29+
sql:
30+
- schema: "query.sql"
31+
queries: "query.sql"
32+
engine: "postgresql"
33+
database:
34+
uri: "postgresql://postgres:postgres@localhost:5432/postgres"
35+
gen:
36+
go:
37+
package: "db"
38+
out: "db"
39+
rules:
40+
- has-index
41+
rules:
42+
- name: has-index
43+
rule: >
44+
query.sql.startsWith("SELECT") &&
45+
!(postgresql.explain.plan.plans.all(p, has(p.index_name) || p.plans.all(p, has(p.index_name))))
46+
```
47+
48+
The expression environment has two variables containing `EXPLAIN ...` output, `postgresql.explain` and `mysql.explain`. `sqlc` only populates the variable associated with your configured database engine, and only when you have a [database connection configured](../reference/config.html#database).
49+
50+
For the `postgresql` engine, `sqlc` runs
51+
52+
```sql
53+
EXPLAIN (ANALYZE false, VERBOSE, COSTS, SETTINGS, BUFFERS, FORMAT JSON) ...
54+
```
55+
56+
where `"..."` is your query string, and parses the output into a [`PostgreSQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.PostgreSQLExplain) proto message.
57+
58+
For the `mysql` engine, `sqlc` runs
59+
60+
```sql
61+
EXPLAIN FORMAT=JSON ...
62+
```
63+
64+
where `"..."` is your query string, and parses the output into a [`MySQLExplain`](https://buf.build/sqlc/sqlc/docs/v1.20.0:vet#vet.MySQLExplain) proto message.
65+
66+
These proto message definitions are too long to include here, but you can find them in the `protos` directory within the `sqlc` source tree.
67+
68+
The output from `EXPLAIN ...` depends on the structure of your query so it's a bit difficult to offer generic examples. Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/using-explain.html) and [MySQL documentation](https://dev.mysql.com/doc/refman/en/explain-output.html) for more information.
69+
70+
```yaml
71+
...
72+
rules:
73+
- name: postgresql-query-too-costly
74+
message: "Query cost estimate is too high"
75+
rule: "postgresql.explain.plan.total_cost > 1.0"
76+
- name: postgresql-no-seq-scan
77+
message: "Query plan results in a sequential scan"
78+
rule: "postgresql.explain.plan.node_type == 'Seq Scan'"
79+
- name: mysql-query-too-costly
80+
message: "Query cost estimate is too high"
81+
rule: "has(mysql.explain.query_block.cost_info) && double(mysql.explain.query_block.cost_info.query_cost) > 2.0"
82+
- name: mysql-must-use-primary-key
83+
message: "Query plan doesn't use primary key"
84+
rule: "has(mysql.explain.query_block.table.key) && mysql.explain.query_block.table.key != 'PRIMARY'"
85+
```
86+
87+
When building rules that depend on `EXPLAIN ...` output, it may be helpful to see the actual JSON returned from the database. `sqlc` will print it When you set the environment variable `SQLCDEBUG=dumpexplain=1`. Use this environment variable together with a dummy rule to see `EXPLAIN ...` output for all of your queries.
88+
89+
#### Opting-out of lint rules
90+
91+
For any query, you can tell `sqlc vet` not to evaluate lint rules using the `@sqlc-vet-disable` query annotation.
92+
93+
```sql
94+
/* name: GetAuthor :one */
95+
/* @sqlc-vet-disable */
96+
SELECT * FROM authors
97+
WHERE id = ? LIMIT 1;
98+
```
99+
100+
#### Bulk insert for MySQL
101+
102+
_Developed by [@Jille](https://github.com/Jille)_
103+
104+
MySQL now supports the `:copyfrom` query annotation. The generated code uses the [LOAD DATA](https://dev.mysql.com/doc/refman/8.0/en/load-data.html) command to insert data quickly and efficiently.
105+
106+
Use caution with this feature. Errors and duplicate keys are treated as warnings and insertion will continue, even without an error for some cases. Use this in a transaction and use `SHOW WARNINGS` to check for any problems and roll back if necessary.
107+
108+
Check the [error handling](https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-error-handling) documentation for more information.
109+
110+
```sql
111+
CREATE TABLE foo (a text, b integer, c DATETIME, d DATE);
112+
113+
-- name: InsertValues :copyfrom
114+
INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?);
115+
```
116+
117+
```go
118+
func (q *Queries) InsertValues(ctx context.Context, arg []InsertValuesParams) (int64, error) {
119+
...
120+
}
121+
```
122+
123+
`LOAD DATA` support must be enabled in the MySQL server.
124+
125+
#### CAST support for MySQL
126+
127+
_Developed by [@ryanpbrewster](https://github.com/ryanpbrewster) and [@RadhiFadlillah](https://github.com/RadhiFadlillah)_
128+
129+
`sqlc` now understands `CAST` calls in MySQL queries, offering greater flexibility when generating code for complex queries.
130+
131+
```sql
132+
CREATE TABLE foo (bar BOOLEAN NOT NULL);
133+
134+
-- name: SelectColumnCast :many
135+
SELECT CAST(bar AS BIGINT) FROM foo;
136+
```
137+
138+
```go
139+
package querytest
140+
141+
import (
142+
"context"
143+
)
144+
145+
const selectColumnCast = `-- name: SelectColumnCast :many
146+
SELECT CAST(bar AS BIGINT) FROM foo
147+
`
148+
149+
func (q *Queries) SelectColumnCast(ctx context.Context) ([]int64, error) {
150+
...
151+
}
152+
```
153+
154+
#### SQLite improvements
155+
156+
A slew of fixes landed for our SQLite implementation, bringing it closer to parity with MySQL and PostgreSQL. We want to thank [@orisano](https://github.com/orisano) for their continued dedication to improving `sqlc`'s SQLite support.
157+
158+
### Changes
159+
160+
#### Features
161+
162+
- (debug) Add debug flag and docs for dumping vet rule variables (#2521)
163+
- (mysql) :copyfrom support via LOAD DATA INFILE (#2545)
164+
- (mysql) Implement cast function parser (#2473)
165+
- (postgresql) Add support for PostgreSQL multi-dimensional arrays (#2338)
166+
- (sql/catalog) Support ALTER TABLE IF EXISTS (#2542)
167+
- (sqlite) Virtual tables and fts5 supported (#2531)
168+
- (vet) Add default query parameters for explain queries (#2543)
169+
- (vet) Add output from `EXPLAIN ...` for queries to the CEL program environment (#2489)
170+
- (vet) Introduce a query annotation to opt out of sqlc vet rules (#2474)
171+
- Parse comment lines starting with `@symbol` as boolean flags associated with a query (#2464)
172+
173+
#### Bug Fixes
174+
175+
- (codegen/golang) Fix sqlc.embed to work with pq.Array (#2544)
176+
- (compiler) Correctly validate alias in order/group by clauses for joins (#2537)
177+
- (engine/sqlite) Added function to convert cast node (#2470)
178+
- (engine/sqlite) Fix join_operator rule (#2434)
179+
- (engine/sqlite) Fix table_alias rules (#2465)
180+
- (engine/sqlite) Fixed IN operator precedence (#2428)
181+
- (engine/sqlite) Fixed to be able to find relation from WITH clause (#2444)
182+
- (engine/sqlite) Lowercase ast.ResTarget.Name (#2433)
183+
- (engine/sqlite) Put logging statement behind debug flag (#2488)
184+
- (engine/sqlite) Support for repeated table_option (#2482)
185+
- (mysql) Generate unsigned param (#2522)
186+
- (sql/catalog) Support pg_dump output (#2508)
187+
- (sqlite) Code generation for sqlc.slice (#2431)
188+
- (vet) Clean up unnecessary `prepareable()` func and a var name (#2509)
189+
- (vet) Query.cmd was always set to ":" (#2525)
190+
- (vet) Report an error when a query is unpreparable, close prepared statement connection (#2486)
191+
- (vet) Split vet messages out of codegen.proto (#2511)
192+
193+
#### Documentation
194+
195+
- Add a description to the document for cases when a query result has no rows (#2462)
196+
- Update copyright and author (#2490)
197+
- Add example sqlc.yaml for migration parsing (#2479)
198+
- Small updates (#2506)
199+
- Point GitHub links to new repository location (#2534)
200+
201+
#### Miscellaneous Tasks
202+
203+
- Rename kyleconroy/sqlc to sqlc-dev/sqlc (#2523)
204+
- (proto) Reformat protos using `buf format -w` (#2536)
205+
- Update FEATURE_REQUEST.yml to include SQLite engine option
206+
- Finish migration to sqlc-dev/sqlc (#2548)
207+
- (compiler) Remove some duplicate code (#2546)
208+
209+
#### Testing
210+
211+
- Add profiles to docker compose (#2503)
212+
213+
#### Build
214+
215+
- Run all supported versions of MySQL / PostgreSQL (#2463)
216+
- (deps) Bump pygments from 2.7.4 to 2.15.0 in /docs (#2485)
217+
- (deps) Bump github.com/jackc/pgconn from 1.14.0 to 1.14.1 (#2483)
218+
- (deps) Bump github.com/google/cel-go from 0.16.0 to 0.17.1 (#2484)
219+
- (docs) Check Python dependencies via dependabot (#2497)
220+
- (deps) Bump idna from 2.10 to 3.4 in /docs (#2499)
221+
- (deps) Bump packaging from 20.9 to 23.1 in /docs (#2498)
222+
- (deps) Bump pygments from 2.15.0 to 2.15.1 in /docs (#2500)
223+
- (deps) Bump certifi from 2022.12.7 to 2023.7.22 in /docs (#2504)
224+
- (deps) Bump sphinx from 4.4.0 to 6.1.0 in /docs (#2505)
225+
- Add psql and mysqlsh to devenv (#2507)
226+
- (deps) Bump urllib3 from 1.26.5 to 2.0.4 in /docs (#2516)
227+
- (deps) Bump chardet from 4.0.0 to 5.1.0 in /docs (#2517)
228+
- (deps) Bump snowballstemmer from 2.1.0 to 2.2.0 in /docs (#2519)
229+
- (deps) Bump pytz from 2021.1 to 2023.3 in /docs (#2520)
230+
- (deps) Bump sphinxcontrib-htmlhelp from 2.0.0 to 2.0.1 in /docs (#2518)
231+
- (deps) Bump pyparsing from 2.4.7 to 3.1.0 in /docs (#2530)
232+
- (deps) Bump alabaster from 0.7.12 to 0.7.13 in /docs (#2526)
233+
- (docs) Ignore updates for sphinx (#2532)
234+
- (deps) Bump babel from 2.9.1 to 2.12.1 in /docs (#2527)
235+
- (deps) Bump sphinxcontrib-applehelp from 1.0.2 to 1.0.4 in /docs (#2533)
236+
- (deps) Bump google.golang.org/grpc from 1.56.2 to 1.57.0 (#2535)
237+
- (deps) Bump pyparsing from 3.1.0 to 3.1.1 in /docs (#2547)
238+
239+
4240
## [1.19.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.1)
5241
Released 2023-07-13
6242

examples/authors/mysql/db.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/authors/mysql/models.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/authors/mysql/query.sql.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/authors/postgresql/db.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/authors/postgresql/models.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/authors/postgresql/query.sql.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/authors/sqlite/db.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/authors/sqlite/models.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/authors/sqlite/query.sql.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/batch/postgresql/batch.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/batch/postgresql/db.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/batch/postgresql/models.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/batch/postgresql/querier.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/batch/postgresql/query.sql.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/booktest/mysql/db.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)