|
1 | 1 | # Changelog
|
2 | 2 | All notable changes to this project will be documented in this file.
|
3 | 3 |
|
| 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 | + |
4 | 240 | ## [1.19.1](https://github.com/sqlc-dev/sqlc/releases/tag/v1.19.1)
|
5 | 241 | Released 2023-07-13
|
6 | 242 |
|
|
0 commit comments