Skip to content

Commit 6d9485f

Browse files
committed
Merge upstream/main into feat/postgresql-merge-support
2 parents a10ebde + 50989da commit 6d9485f

460 files changed

Lines changed: 18166 additions & 94257 deletions

File tree

Some content is hidden

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

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
runs-on: ${{ matrix.os }}
1111
steps:
1212
- uses: actions/checkout@v7
13-
- uses: actions/setup-go@v6
13+
- uses: actions/setup-go@v7
1414
with:
15-
go-version: '1.26.4'
15+
go-version: '1.26.5'
1616
- name: install ./...
1717
run: go build ./...
1818
env:

.github/workflows/ci-kotlin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v7
20-
- uses: actions/setup-go@v6
20+
- uses: actions/setup-go@v7
2121
with:
22-
go-version: '1.26.4'
22+
go-version: '1.26.5'
2323
- name: install ./...
2424
run: go install ./...
2525
- uses: actions/checkout@v7

.github/workflows/ci-python.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v7
20-
- uses: actions/setup-go@v6
20+
- uses: actions/setup-go@v7
2121
with:
22-
go-version: '1.26.4'
22+
go-version: '1.26.5'
2323
- name: install ./...
2424
run: go install ./...
2525
- uses: actions/checkout@v7

.github/workflows/ci-typescript.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v7
20-
- uses: actions/setup-go@v6
20+
- uses: actions/setup-go@v7
2121
with:
22-
go-version: '1.26.4'
22+
go-version: '1.26.5'
2323
- name: install ./...
2424
run: go install ./...
2525
- uses: actions/checkout@v7

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
runs-on: ubuntu-24.04
1515
steps:
1616
- uses: actions/checkout@v7
17-
- uses: actions/setup-go@v6
17+
- uses: actions/setup-go@v7
1818
with:
19-
go-version: '1.26.4'
19+
go-version: '1.26.5'
2020
- run: go build ./...
2121
env:
2222
CGO_ENABLED: "0"
@@ -26,9 +26,9 @@ jobs:
2626
runs-on: ubuntu-24.04
2727
steps:
2828
- uses: actions/checkout@v7
29-
- uses: actions/setup-go@v6
29+
- uses: actions/setup-go@v7
3030
with:
31-
go-version: '1.26.4'
31+
go-version: '1.26.5'
3232

3333
- name: install gotestsum
3434
run: go install gotest.tools/gotestsum@latest

.github/workflows/gen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
1919
steps:
2020
- uses: actions/checkout@v7
21-
- uses: actions/setup-go@v6
21+
- uses: actions/setup-go@v7
2222
with:
2323
go-version-file: go.mod
2424
check-latest: true

CLAUDE.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,23 @@ go test -v ./internal/config -run TestConfig
8989
go test -race ./internal/config
9090
```
9191

92-
## Test Types
92+
## Testing Strategy
9393

94-
### 1. Unit Tests
94+
**Cover new work with end-to-end tests, not unit tests.** A change to the
95+
compiler, an engine, the analysis core or codegen is exercised by running sqlc
96+
the way a user does — a schema, a query file and a committed golden output —
97+
so the test says what sqlc produces rather than what an internal function
98+
returns. Internal APIs move around; the SQL that goes in and the output that
99+
comes out is the contract worth pinning down.
95100

96-
- **Location:** Throughout the codebase as `*_test.go` files
97-
- **Run without:** Database or external dependencies
98-
- **Examples:**
99-
- `/internal/config/config_test.go` - Configuration parsing
100-
- `/internal/compiler/selector_test.go` - Compiler logic
101-
- `/internal/metadata/metadata_test.go` - Query metadata parsing
101+
Adding coverage means adding a directory under `/internal/endtoend/testdata/`,
102+
not a `*_test.go` next to the code. Reach for a unit test only when the
103+
behavior genuinely cannot be reached through the CLI, and say why in the test.
102104

103-
### 2. End-to-End Tests
105+
Some `*_test.go` files predate this and remain; they are not a precedent for
106+
new ones.
107+
108+
### End-to-End Tests
104109

105110
- **Location:** `/internal/endtoend/`
106111
- **Requirements:** `--tags=examples` flag and running databases
@@ -111,7 +116,15 @@ go test -race ./internal/config
111116
- `TestJsonSchema` - JSON schema validation
112117
- `TestExamplesVet` - Static analysis tests
113118

114-
### 3. Example Tests
119+
A case is a directory holding the inputs and the expected output. `exec.json`
120+
names the command and its arguments — omit it and the case runs `generate`,
121+
comparing the generated files against the ones committed alongside; give it
122+
`{"command": "analyze", "args": [...]}` and the case compares the command's
123+
stdout against `stdout.txt`. A case that is expected to fail commits its
124+
`stderr.txt`. Regenerate a golden by running the command in its directory and
125+
writing the output back over the committed file.
126+
127+
### Example Tests
115128

116129
- **Location:** `/examples/` directory
117130
- **Requirements:** Tagged with "examples", requires live databases
@@ -183,6 +196,9 @@ MYSQL_SERVER_URI="root:mysecretpassword@tcp(127.0.0.1:3306)/mysql?multiStatement
183196
- `/postgresql/` - PostgreSQL parser and converter
184197
- `/dolphin/` - MySQL parser (uses TiDB parser)
185198
- `/sqlite/` - SQLite parser
199+
- `<engine>/dialect/` - The engine's type system and standard library, as
200+
JSONL read by `/internal/core/seed`
201+
- `/internal/core/` - The analysis core: catalog, analyzer and dialect seeds
186202
- `/internal/compiler/` - Query compilation logic
187203
- `/internal/codegen/` - Code generation for different languages
188204
- `/internal/config/` - Configuration file parsing
@@ -232,9 +248,10 @@ go run ./cmd/sqlc-test-setup start
232248
## Tips for Contributors
233249

234250
1. **Run tests before committing:** `go test --tags=examples -timeout 20m ./...`
235-
2. **Check for race conditions:** Use `-race` flag when testing concurrent code
236-
3. **Use specific package tests:** Faster iteration during development
237-
4. **Read existing tests:** Good examples in `/internal/engine/postgresql/*_test.go`
251+
2. **Cover new behavior end to end:** Add a case under `/internal/endtoend/testdata/`
252+
3. **Check for race conditions:** Use `-race` flag when testing concurrent code
253+
4. **Iterate on one case:** `go test ./internal/endtoend -run 'TestReplay/base/<case>'`
254+
5. **Read existing cases:** `/internal/endtoend/testdata/` has one per feature
238255

239256
## Git Workflow
240257

docs/howto/analyze.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ Unlike [`generate`](generate.md), this command does not require a configuration
77
file and does not connect to a database. It uses sqlc's native static analysis
88
to infer types directly from the provided schema.
99

10+
Every dialect is analyzed by the same engine-neutral analysis core: the schema
11+
is loaded into a catalog seeded with the dialect's types, operators and
12+
functions, and each query is resolved against it. `generate` still uses each
13+
engine's own analysis path, so the two can report a type differently — most
14+
visibly, `analyze` reports type names as the catalog stores them, in lower
15+
case.
16+
1017
## Usage
1118

1219
```sh
@@ -18,8 +25,8 @@ provided. The schema is always read from the `--schema` file.
1825

1926
## Flags
2027

21-
- `--dialect`, `-d` - The SQL dialect to use. One of `postgresql`, `mysql`, or
22-
`sqlite`. Required.
28+
- `--dialect`, `-d` - The SQL dialect to use. One of `postgresql`, `mysql`,
29+
`sqlite`, `clickhouse`, or `googlesql`. Required.
2330
- `--schema`, `-s` - Path to the schema (DDL) file. Required.
2431
- `--ast` - Include each statement's AST in the output. Defaults to `false`.
2532

docs/howto/parse.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ provided.
2020
## Flags
2121

2222
- `--dialect`, `-d` - The SQL dialect to use. One of `postgresql`, `mysql`,
23-
`sqlite`, or `clickhouse`. Required.
23+
`sqlite`, `clickhouse`, or `googlesql`. Required.
2424

2525
## Examples
2626

docs/reference/environment-variables.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,26 @@ they are introduced.
2020
## SQLCCACHE
2121

2222
The `SQLCCACHE` environment variable dictates where `sqlc` will store cached
23-
WASM-based plugins and modules. By default `sqlc` follows the [XDG Base
24-
Directory
23+
data. By default `sqlc` follows the [XDG Base Directory
2524
Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).
2625

26+
The cache is designed after Bazel's local disk cache and has three parts:
27+
28+
- `cas/` — a content-addressable store holding blobs (query analysis
29+
results, WASM plugin binaries, compiled WASM machine code) keyed by the
30+
SHA-256 hash of their contents. A remotely fetched plugin's address is
31+
exactly the checksum declared in the configuration file, so it is loaded
32+
directly by that address.
33+
- `ac/` — an action cache mapping the digest of a unit of cacheable work and
34+
its inputs (analyzing a query against a schema, compiling a WASM module to
35+
machine code) to the CAS digests of its outputs.
36+
- `exec/` — per-action directories where cached output trees are
37+
materialized for tools that read them from disk, such as the
38+
[wazero](https://wazero.io) runtime's compilation cache.
39+
40+
The entire directory is safe to delete at any time; sqlc will rebuild it as
41+
needed.
42+
2743
## SQLCDEBUG
2844

2945
The `SQLCDEBUG` variable controls debugging variables within the runtime. It is

0 commit comments

Comments
 (0)