Skip to content

Commit aebcc5c

Browse files
committed
fix
1 parent 32bf962 commit aebcc5c

9 files changed

Lines changed: 96 additions & 193 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# Fork with engine support: https://github.com/ydb-platform/sqlc, branch engine-plugin.
66
# Optional build-arg: ENGINE_PLUGIN_REF=engine-plugin (branch/tag to clone).
77

8-
ARG GO_VERSION=1.24
8+
# Must satisfy sqlc-ydb/go.mod (e.g. go 1.26.0) and the cloned engine-plugin go version.
9+
ARG GO_VERSION=1.26
910
ARG ENGINE_PLUGIN_REF=engine-plugin
1011

1112
# --- Build sqlc and sqlc-ydb plugins ---

Makefile

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# sqlc-ydb: engine plugin + ydb-go-sdk codegen plugin for sqlc (v2 config)
22
#
33
# Prerequisites:
4-
# - Go 1.24+
4+
# - Go 1.26+ (match go.mod)
55
# - protoc + protoc-gen-go (for proto). go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
66
# - go mod download (so SQLC_MOD_DIR is available for proto)
7-
# - sqlc with plugin support (for examples), on PATH
7+
# - ../engine-plugin (clone next to this repo) — required for `make build-sqlc` / `make examples`
88
#
99
# Overrides:
10-
# BINDIR where to install plugin binaries (default: bin)
11-
# SQLC sqlc binary for examples (default: bin/sqlc if build-sqlc was run, else sqlc)
10+
# BINDIR where to install plugin binaries (default: bin)
11+
# EXAMPLES_SQLC sqlc binary for `make examples` (default: $(BINDIR)/sqlc from build-sqlc)
1212
#
13-
# Default: show help. Run 'make build' then 'make build-sqlc' then 'make examples' to generate code.
14-
# build-sqlc builds sqlc from ../engine-plugin (required for plugin support).
13+
# Default: show help. `make examples` runs `build` + `build-sqlc` and always uses plugin-aware sqlc
14+
# from $(BINDIR)/sqlc. Using the system `sqlc` without engine plugins causes obscure errors
15+
# (e.g. JSON parse failures on protobuf stdin).
1516

1617
REPO_ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
17-
BINDIR ?= bin
18-
# Prefer bin/sqlc from build-sqlc when present
19-
SQLC ?= $(firstword $(wildcard $(REPO_ROOT)$(BINDIR)/sqlc) sqlc)
18+
BINDIR ?= bin
2019
ENGINE_PLUGIN_DIR := $(REPO_ROOT)../engine-plugin
20+
EXAMPLES_SQLC ?= $(REPO_ROOT)$(BINDIR)/sqlc
2121

2222
# Use codegen.proto from the sqlc module (via replace => ../engine-plugin or go get).
2323
SQLC_MOD_DIR := $(shell go list -m -f '{{.Dir}}' github.com/sqlc-dev/sqlc)
@@ -40,7 +40,7 @@ PLUGIN_OUTPUTS := ydb-go-sdk ydb-database-sql ydb-python-sdk
4040

4141
DOCKER_IMAGE ?= sqlc-ydb
4242

43-
.PHONY: all proto build build-engine build-codegen build-codegen-dbsql build-codegen-pysdk build-sqlc examples docker-build clean help
43+
.PHONY: all proto build build-engine build-codegen build-codegen-dbsql build-codegen-pysdk build-sqlc examples docker docker-build clean help
4444

4545
all: help
4646

@@ -53,11 +53,11 @@ help:
5353
@echo " build-codegen-pysdk - build sqlc-gen-ydb-python-sdk into $(BINDIR)/ (depends on proto)"
5454
@echo " build - proto + build all plugins (ydb-go-sdk, ydb-database-sql, ydb-python-sdk)"
5555
@echo " build-sqlc - build sqlc from ../engine-plugin into $(BINDIR)/sqlc (needed for examples)"
56-
@echo " examples - run 'sqlc generate' in each example (EXAMPLES=$(EXAMPLES)); outputs: $(PLUGIN_OUTPUTS)"
56+
@echo " examples - build-sqlc + run '$(BINDIR)/sqlc generate' in each example (EXAMPLES=$(EXAMPLES))"
5757
@echo " docker-build - build Docker image with sqlc + plugins (DOCKER_IMAGE=$(DOCKER_IMAGE))"
5858
@echo " clean - remove $(BINDIR)/ and generated plugin dirs under examples/"
5959
@echo ""
60-
@echo "Overrides: BINDIR=$(BINDIR) SQLC=$(SQLC) DOCKER_IMAGE=$(DOCKER_IMAGE)"
60+
@echo "Overrides: BINDIR=$(BINDIR) EXAMPLES_SQLC=$(EXAMPLES_SQLC) DOCKER_IMAGE=$(DOCKER_IMAGE)"
6161

6262
# Generate plugin proto Go from the sqlc module's codegen.proto (via go get / replace).
6363
# Output goes to internal/codegen/pb with package pb.
@@ -112,20 +112,23 @@ $(BINDIR):
112112
mkdir -p $(BINDIR)
113113

114114
# Run sqlc generate in each example dir. One run per example generates all plugin outputs (ydb-go-sdk, ydb-database-sql).
115-
examples: build
116-
@which $(SQLC) >/dev/null 2>/dev/null || (echo "error: sqlc not found. Run 'make build-sqlc' or set SQLC to a plugin-aware sqlc binary" >&2; exit 1)
115+
examples: build build-sqlc
116+
@test -x "$(EXAMPLES_SQLC)" || (echo "error: $(EXAMPLES_SQLC) not found or not executable (build-sqlc failed?)" >&2; exit 1)
117117
@for ex in $(EXAMPLES); do \
118118
echo "sqlc generate in examples/$$ex ..."; \
119-
(cd $(REPO_ROOT)examples/$$ex && PATH="$(REPO_ROOT)$(BINDIR):$$PATH" $(SQLC) generate) || exit 1; \
119+
(cd $(REPO_ROOT)examples/$$ex && PATH="$(REPO_ROOT)$(BINDIR):$$PATH" "$(EXAMPLES_SQLC)" generate) || exit 1; \
120120
done
121121
@echo "ok: examples generated ($(EXAMPLES) -> $(PLUGIN_OUTPUTS))"
122122

123123
# Build Docker image: sqlc (from engine-plugin) + sqlc-engine-ydb + codegen plugins.
124124
# Optional: DOCKER_IMAGE=name, ENGINE_PLUGIN_REF=branch (docker build --build-arg).
125-
docker:
125+
docker-build:
126126
docker build -t $(DOCKER_IMAGE) .
127127
@echo "ok: image $(DOCKER_IMAGE)"
128128

129+
# Alias for older scripts that used `make docker`.
130+
docker: docker-build
131+
129132
clean:
130133
rm -rf $(REPO_ROOT)$(BINDIR)
131134
@for ex in $(EXAMPLES); do \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@ The `examples/authors` project uses the v2 config with the **sqlc-engine-ydb** e
167167
make examples
168168
```
169169

170-
Generated files appear under each example: `ydb-go-sdk/` and `ydb-database-sql/` (Go: `models.go`, `db.go`, `queries.sql.go`), `ydb-python-sdk/` (Python: `models.py`, `queries.py`, `__init__.py`). The Makefile uses `bin/sqlc` from `make build-sqlc` by default; override with `make examples SQLC=/path/to/sqlc`.
170+
Generated files appear under each example: `ydb-go-sdk/` and `ydb-database-sql/` (Go: `models.go`, `db.go`, `queries.sql.go`), `ydb-python-sdk/` (Python: `models.py`, `queries.py`, `__init__.py`). `make examples` runs `build-sqlc` and uses **`bin/sqlc`** from **engine-plugin** (required: engine + process plugins). Override with `make examples EXAMPLES_SQLC=/path/to/sqlc` if needed.

examples/authors/ydb-database-sql/retry_test.go

Lines changed: 0 additions & 107 deletions
This file was deleted.

examples/booktest/ydb-go-sdk/db.go

Lines changed: 4 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)