Skip to content

Commit b9bf2b3

Browse files
authored
Merge branch 'sqlc-dev:main' into engine-plugin
2 parents b1c193a + e209d86 commit b9bf2b3

59 files changed

Lines changed: 2481 additions & 87 deletions

Some content is hidden

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

.github/workflows/buf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v6
11+
- uses: actions/checkout@v7
1212
- uses: bufbuild/buf-setup-action@v1
1313
- uses: bufbuild/buf-lint-action@v1

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
name: build ${{ matrix.os }}
1010
runs-on: ${{ matrix.os }}
1111
steps:
12-
- uses: actions/checkout@v6
12+
- uses: actions/checkout@v7
1313
- uses: actions/setup-go@v6
1414
with:
1515
go-version: '1.26.4'

.github/workflows/ci-kotlin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
name: test
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v6
19+
- uses: actions/checkout@v7
2020
- uses: actions/setup-go@v6
2121
with:
2222
go-version: '1.26.4'
2323
- name: install ./...
2424
run: go install ./...
25-
- uses: actions/checkout@v6
25+
- uses: actions/checkout@v7
2626
with:
2727
repository: sqlc-dev/sqlc-gen-kotlin
2828
path: kotlin

.github/workflows/ci-python.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
name: test
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v6
19+
- uses: actions/checkout@v7
2020
- uses: actions/setup-go@v6
2121
with:
2222
go-version: '1.26.4'
2323
- name: install ./...
2424
run: go install ./...
25-
- uses: actions/checkout@v6
25+
- uses: actions/checkout@v7
2626
with:
2727
repository: sqlc-dev/sqlc-gen-python
2828
path: python

.github/workflows/ci-typescript.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
name: test
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v6
19+
- uses: actions/checkout@v7
2020
- uses: actions/setup-go@v6
2121
with:
2222
go-version: '1.26.4'
2323
- name: install ./...
2424
run: go install ./...
25-
- uses: actions/checkout@v6
25+
- uses: actions/checkout@v7
2626
with:
2727
repository: sqlc-dev/sqlc-gen-typescript
2828
path: typescript

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: build ${{ matrix.goos }}/${{ matrix.goarch }}
1414
runs-on: ubuntu-24.04
1515
steps:
16-
- uses: actions/checkout@v6
16+
- uses: actions/checkout@v7
1717
- uses: actions/setup-go@v6
1818
with:
1919
go-version: '1.26.4'
@@ -25,7 +25,7 @@ jobs:
2525
test:
2626
runs-on: ubuntu-24.04
2727
steps:
28-
- uses: actions/checkout@v6
28+
- uses: actions/checkout@v7
2929
- uses: actions/setup-go@v6
3030
with:
3131
go-version: '1.26.4'

.github/workflows/gen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
# needed because the postgres container does not provide a healthcheck
1818
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
1919
steps:
20-
- uses: actions/checkout@v6
20+
- uses: actions/checkout@v7
2121
- uses: actions/setup-go@v6
2222
with:
2323
go-version-file: go.mod

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# STEP 1: Build sqlc
2-
FROM golang:1.26.4 AS builder
2+
FROM golang:1.26.5 AS builder
33

44
COPY . /workspace
55
WORKDIR /workspace

docs/howto/analyze.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# `analyze` - Analyzing query result types
2+
3+
`sqlc analyze` analyzes a query against a schema and prints the inferred result
4+
columns and parameters as a single JSON document.
5+
6+
Unlike [`generate`](generate.md), this command does not require a configuration
7+
file and does not connect to a database. It uses sqlc's native static analysis
8+
to infer types directly from the provided schema.
9+
10+
## Usage
11+
12+
```sh
13+
sqlc analyze --dialect <dialect> --schema <schema-file> [query-file]
14+
```
15+
16+
The query is read from the given file, or from standard input when no file is
17+
provided. The schema is always read from the `--schema` file.
18+
19+
## Flags
20+
21+
- `--dialect`, `-d` - The SQL dialect to use. One of `postgresql`, `mysql`, or
22+
`sqlite`. Required.
23+
- `--schema`, `-s` - Path to the schema (DDL) file. Required.
24+
- `--ast` - Include each statement's AST in the output. Defaults to `false`.
25+
26+
## Examples
27+
28+
Given a schema in `schema.sql`:
29+
30+
```sql
31+
CREATE TABLE authors (
32+
id BIGSERIAL PRIMARY KEY,
33+
name text NOT NULL,
34+
bio text
35+
);
36+
```
37+
38+
and a query in `query.sql`:
39+
40+
```sql
41+
-- name: GetAuthor :one
42+
SELECT * FROM authors WHERE id = $1;
43+
```
44+
45+
Running:
46+
47+
```sh
48+
sqlc analyze --dialect postgresql --schema schema.sql query.sql
49+
```
50+
51+
reports the result columns and parameters:
52+
53+
```json
54+
[
55+
{
56+
"name": "GetAuthor",
57+
"cmd": ":one",
58+
"columns": [
59+
{
60+
"name": "id",
61+
"data_type": "bigserial",
62+
"not_null": true,
63+
"is_array": false,
64+
"table": "authors"
65+
},
66+
{
67+
"name": "name",
68+
"data_type": "text",
69+
"not_null": true,
70+
"is_array": false,
71+
"table": "authors"
72+
},
73+
{
74+
"name": "bio",
75+
"data_type": "text",
76+
"not_null": false,
77+
"is_array": false,
78+
"table": "authors"
79+
}
80+
],
81+
"params": [
82+
{
83+
"number": 1,
84+
"column": {
85+
"name": "id",
86+
"data_type": "bigserial",
87+
"not_null": true,
88+
"is_array": false,
89+
"table": "authors"
90+
}
91+
}
92+
]
93+
}
94+
]
95+
```
96+
97+
Pass `--ast` to also include each statement's parsed AST under an `ast` key.

docs/howto/parse.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# `parse` - Parsing SQL into an AST
2+
3+
`sqlc parse` parses SQL from a file or standard input and prints the abstract
4+
syntax tree (AST) as a single JSON document. It does not require a configuration
5+
file or a database connection.
6+
7+
Each statement is reported with its sqlc query name and command (when the
8+
statement carries a [`-- name:`](../reference/query-annotations.md) annotation)
9+
alongside its AST.
10+
11+
## Usage
12+
13+
```sh
14+
sqlc parse --dialect <dialect> [file]
15+
```
16+
17+
The SQL is read from the given file, or from standard input when no file is
18+
provided.
19+
20+
## Flags
21+
22+
- `--dialect`, `-d` - The SQL dialect to use. One of `postgresql`, `mysql`,
23+
`sqlite`, or `clickhouse`. Required.
24+
25+
## Examples
26+
27+
Parse a query file:
28+
29+
```sh
30+
sqlc parse --dialect postgresql query.sql
31+
```
32+
33+
Parse SQL piped via standard input:
34+
35+
```sh
36+
echo "SELECT 1;" | sqlc parse --dialect mysql
37+
```
38+
39+
The output is a JSON array with one object per statement:
40+
41+
```json
42+
[
43+
{
44+
"name": "GetAuthor",
45+
"cmd": ":one",
46+
"ast": {
47+
"Stmt": {
48+
"...": "..."
49+
},
50+
"StmtLocation": 0,
51+
"StmtLen": 42
52+
}
53+
}
54+
]
55+
```
56+
57+
Statements without a `-- name:` annotation (for example schema DDL) omit the
58+
`name` and `cmd` fields.

0 commit comments

Comments
 (0)