-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add release notes for v1.19.0 (#2406)
* docs: Add v1.19 release notes * docs: Add docs for sqlc vet
- Loading branch information
1 parent
5134490
commit 7ca892f
Showing
16 changed files
with
562 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
.wy-side-nav-search img { | ||
padding: 5px 60px !important; | ||
} | ||
|
||
#banner { | ||
text-align: center; | ||
background: #2980b9; | ||
border: 1px solid rgb(52, 49, 49); | ||
color: #F0F0F4; | ||
padding: 10px; | ||
margin-bottom: 1.618em; | ||
} | ||
|
||
#banner > div > a { | ||
color: #F0F0F4; | ||
text-decoration: underline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends "!breadcrumbs.html" %} | ||
|
||
{% block breadcrumbs %} | ||
{% if show_banner %} | ||
<header id="banner"> | ||
<div>✨ We're now working full-time on sqlc. Read more <a href="https://sqlc.dev/posts/2023/07/06/working-on-sqlc-full-time">here</a>.</div> | ||
</header> | ||
{% endif %} | ||
{{ super() }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{% extends "!layout.html" %} | ||
|
||
{% block extrahead %} | ||
<script defer data-domain="docs.sqlc.dev" src="https://plausible.io/js/plausible.js"></script> | ||
{{ super() }} | ||
{% endblock %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Suggested CI/CD setup | ||
|
||
If your project has more than a single developer, we suggest running `sqlc` as | ||
part of your CI/CD pipeline. The two commands you'll want to run are `diff` and `vet` | ||
|
||
`sqlc diff` ensures that code is up to date. New developers to a project may | ||
forget to run `sqlc generate`. They also might edit generated code. `diff` will | ||
catch both scenarios. | ||
|
||
```diff | ||
% sqlc-dev diff | ||
--- a/postgresql/query.sql.go | ||
+++ b/postgresql/query.sql.go | ||
@@ -55,7 +55,7 @@ | ||
|
||
const listAuthors = `-- name: ListAuthors :many | ||
SELECT id, name, bio FROM authors | ||
-ORDER BY name | ||
+ORDER BY bio | ||
` | ||
``` | ||
|
||
`sqlc vet` runs a set of lint checks against your SQL queries. These checks are | ||
helpful in catching anti-patterns before they make it into production. Please | ||
see the [vet](vet.md) documentation for a complete guide on adding checks to your | ||
project. | ||
|
||
## General setup | ||
|
||
Install `sqlc` using the [suggested instructions](../overview/install). | ||
|
||
Create two steps in your pipelines, one for `sqlc diff`and one for `sqlc vet`. | ||
|
||
## GitHub Actions | ||
|
||
We provide the [setup-sqlc](https://github.com/marketplace/actions/setup-sqlc) | ||
GitHub Action to install `sqlc`. The action uses the built-in | ||
[tool-cache](https://github.com/actions/toolkit/blob/main/packages/tool-cache/README.md) | ||
to speed up the installation process. | ||
|
||
The following workflow runs `sqlc diff` on every push. | ||
|
||
```yaml | ||
name: sqlc | ||
on: [push] | ||
jobs: | ||
diff: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: sqlc-dev/setup-sqlc@v3 | ||
with: | ||
sqlc-version: '1.19.0' | ||
- run: sqlc diff | ||
``` | ||
|
||
We also encourage running [`sqlc vet`](vet.md). To get the most value out of | ||
`vet`, you'll want to set up a running database. | ||
|
||
```yaml | ||
name: sqlc | ||
on: [push] | ||
jobs: | ||
vet: | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: "postgres:15" | ||
env: | ||
POSTGRES_DB: postgres | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_USER: postgres | ||
ports: | ||
- 5432:5432 | ||
# needed because the postgres container does not provide a healthcheck | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
env: | ||
PG_PORT: ${{ job.services.postgres.ports['5432'] }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: sqlc-dev/setup-sqlc@v3 | ||
with: | ||
sqlc-version: '1.19.0' | ||
# Connect and migrate your database here. This is an example which runs | ||
# commands from a `schema.sql` file. | ||
- run: psql -h localhost -U postgres -p $PG_PORT -d postgres -f schema.sql | ||
env: | ||
PGPASSWORD: postgres | ||
- run: sqlc vet | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Linting queries | ||
|
||
*Added in v1.19.0* | ||
|
||
`sqlc vet` runs queries through a set of lint rules. | ||
|
||
Rules are defined in the `sqlc` [configuration](../reference/config) file. They consist | ||
of a name, message, and an expression. If the expression evaluates to `true`, an | ||
error is reported. These expressions are evaluated using | ||
[cel-go](https://github.com/google/cel-go). | ||
|
||
Each expression has access to a query object, which is defined as the following | ||
struct: | ||
|
||
```proto | ||
message Config | ||
{ | ||
string version = 1; | ||
string engine = 2 ; | ||
repeated string schema = 3; | ||
repeated string queries = 4; | ||
} | ||
message Query | ||
{ | ||
// SQL body | ||
string sql = 1; | ||
// Name of the query | ||
string name = 2; | ||
// One of :many, :one, :exec, etc. | ||
string cmd = 3; | ||
// Query parameters, if any | ||
repeated Parameter params = 4; | ||
} | ||
message Parameter | ||
{ | ||
int32 number = 1; | ||
} | ||
``` | ||
|
||
This struct may be expanded in the future to include more query information. | ||
We may also add information from a running database, such as the result from | ||
`EXPLAIN`. | ||
|
||
While these examples are simplistic, they give you an idea on what types of | ||
rules you can write. | ||
|
||
```yaml | ||
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" | ||
``` | ||
|
||
## Built-in rules | ||
|
||
### sqlc/db-prepare | ||
|
||
When a [database](../reference/config.html#database) in configured, the `sqlc/db-preapre` | ||
rule will attempt to prepare each of your queries against the connected | ||
database. Any failures will be reported to standard error. | ||
|
||
```yaml | ||
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](https://github.com/kyleconroy/sqlc/blob/main/examples/authors/sqlc.yaml). | ||
|
||
Please note that `sqlc` does not manage or migrate the database. Use your | ||
migration tool of choice to create the necessary database tables and objects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.