Skip to content
Merged
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
44 changes: 44 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Contributing

## Building from source

```sh
make all # produces bin/sqlc-gen-go and bin/sqlc-gen-go.wasm
```

To use a local build:

```yaml
plugins:
- name: golang
wasm:
url: file:///path/to/bin/sqlc-gen-go.wasm
sha256: "" # optional since sqlc v1.24.0
```

## Testing

```sh
make test # plugin internals + generated-code unit tests (no DB)
make example-e2e # end-to-end tests against a real PostgreSQL database
```

Run a single test:

```sh
go test ./internal/... -run TestName
```

Run fuzz tests:

```sh
go test ./internal/opts/... -fuzz FuzzOverride
```

## Benchmarks

`emit_dynamic_filter` uses a pre-compiled query (parsed once at init, `Build()` per request) rather than parsing on every call. It is ~14–25× faster than one-shot parsing and matches or beats hand-written builders, with allocations down to 3–10 per call. Source and full numbers: [`example/bench/`](example/bench/).

```sh
cd example && go test ./bench -bench=. -benchmem -run='^$'
```
51 changes: 51 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Migrating from sqlc's built-in Go codegen

Two changes are required:

1. Add a top-level `plugins` entry pointing to the WASM plugin.
2. Replace `gen.go` with `codegen`, referencing the plugin by name. Move all options into the `options` block; `out` moves up one level.

**Before:**
```yaml
sql:
- engine: postgresql
gen:
go:
package: db
out: db
emit_json_tags: true
```

**After:**
```yaml
plugins:
- name: golang
wasm:
url: https://github.com/vtuanjs/sqlc-gen-go/releases/download/v3.0.1/sqlc-gen-go.wasm
sha256: f6a02c8cb363c56bb7a7de1d1012a65e800897696de9d28b938563af02e3ce81
sql:
- engine: postgresql
codegen:
- plugin: golang
out: db
options:
package: db
emit_json_tags: true
```

Global `overrides`/`go` move to `options`/`<plugin-name>`:

```yaml
options:
golang:
rename:
id: "Identifier"
overrides:
- db_type: "timestamptz"
nullable: true
engine: postgresql
go_type:
import: "gopkg.in/guregu/null.v4"
package: "null"
type: "Time"
```
Loading
Loading