Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,45 @@ Test the connection:
mysql -h 127.0.0.1 -u root -pmysecretpassword -e "SELECT VERSION();"
```

### Step 4: Run End-to-End Tests
### Step 4: Install ClickHouse (Optional - for ClickHouse tests)

With both databases running, the test framework automatically detects them:
ClickHouse is required for ClickHouse engine tests. The ClickHouse feature is experimental and requires the `SQLCEXPERIMENT=clickhouse` flag.

**Important:** Use the official ClickHouse repository, not the Ubuntu package (which has an old incompatible version).

```bash
# Add ClickHouse official repository key and source
curl -fsSL https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key | sudo gpg --dearmor -o /usr/share/keyrings/clickhouse-keyring.gpg
ARCH=$(dpkg --print-architecture)
echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg arch=${ARCH}] https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list

# Install ClickHouse from official repo
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y clickhouse-server clickhouse-client

# Start ClickHouse server
sudo clickhouse start
```

Test the connection:

```bash
clickhouse-client --query "SELECT version()"
```

The native database support automatically detects ClickHouse and uses:
- URI: `clickhouse://default:@localhost:9000/default`
- User: `default` (no password)
- Port: 9000

**Note:** ClickHouse tests require setting the experiment flag:
```bash
SQLCEXPERIMENT=clickhouse go test ./internal/endtoend -run "TestReplay/clickhouse" -v
```

### Step 5: Run End-to-End Tests

With the databases running, the test framework automatically detects them:

```bash
# Run all end-to-end tests
Expand All @@ -103,11 +139,12 @@ go test --tags=examples -timeout 20m ./...
```

The native database support (in `internal/sqltest/native/`) automatically:
- Detects running PostgreSQL and MySQL instances
- Detects running PostgreSQL, MySQL, and ClickHouse instances
- Starts services if installed but not running
- Uses standard connection URIs:
- PostgreSQL: `postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable`
- MySQL: `root:mysecretpassword@tcp(127.0.0.1:3306)/mysql`
- ClickHouse: `clickhouse://default:@localhost:9000/default`

### Running Tests

Expand Down Expand Up @@ -193,6 +230,11 @@ The `docker-compose.yml` provides test databases:
- Password: `mysecretpassword`
- Database: `dinotest`

- **ClickHouse** - Port 9000 (experimental, requires `SQLCEXPERIMENT=clickhouse`)
- User: `default`
- Password: (none)
- Database: `default`

### Managing Databases

```bash
Expand Down Expand Up @@ -291,6 +333,7 @@ POSTGRESQL_SERVER_URI="postgres://postgres:mysecretpassword@localhost:5432/postg
- `/postgresql/` - PostgreSQL parser and converter
- `/dolphin/` - MySQL parser (uses TiDB parser)
- `/sqlite/` - SQLite parser
- `/clickhouse/` - ClickHouse parser (uses doubleclick parser, experimental)
- `/internal/compiler/` - Query compilation logic
- `/internal/codegen/` - Code generation for different languages
- `/internal/config/` - Configuration file parsing
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ services:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_USER: postgres

clickhouse:
image: "clickhouse/clickhouse-server:latest"
ports:
- "9000:9000"
- "8123:8123"
restart: always
environment:
CLICKHOUSE_DB: default
CLICKHOUSE_USER: default
CLICKHOUSE_PASSWORD: mysecretpassword
28 changes: 21 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module github.com/sqlc-dev/sqlc

go 1.24.0

toolchain go1.24.1
go 1.24.7

require (
github.com/ClickHouse/clickhouse-go/v2 v2.42.0
github.com/antlr4-go/antlr/v4 v4.13.1
github.com/cubicdaiya/gonp v1.0.4
github.com/davecgh/go-spew v1.1.1
Expand All @@ -22,6 +21,7 @@ require (
github.com/riza-io/grpc-go v0.2.0
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
github.com/sqlc-dev/doubleclick v0.0.0-20251223195122-0076eee94506
github.com/tetratelabs/wazero v1.10.1
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07
github.com/xeipuuv/gojsonschema v1.2.0
Expand All @@ -34,6 +34,12 @@ require (
require (
cel.dev/expr v0.24.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/ClickHouse/ch-go v0.69.0 // indirect
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/go-faster/city v1.0.1 // indirect
github.com/go-faster/errors v0.7.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.3 // indirect
Expand All @@ -43,23 +49,31 @@ require (
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/ncruces/julianday v1.0.0 // indirect
github.com/paulmach/orb v0.12.0 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb // indirect
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
github.com/pingcap/log v1.1.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/segmentio/asm v1.2.1 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
go.opentelemetry.io/otel v1.39.0 // indirect
go.opentelemetry.io/otel/trace v1.39.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.45.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.46.0 // indirect
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.32.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20251022142026-3a174f9686a8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
Expand Down
Loading
Loading