Claude/add duckdb support 011 cu zi cr uy8 smt tk6i2h gn r#4160
Draft
kyleconroy wants to merge 7 commits intomainfrom
Draft
Claude/add duckdb support 011 cu zi cr uy8 smt tk6i2h gn r#4160kyleconroy wants to merge 7 commits intomainfrom
kyleconroy wants to merge 7 commits intomainfrom
Conversation
This commit adds DuckDB as a supported database engine to sqlc by reusing the PostgreSQL parser and catalog while implementing a custom analyzer that connects to an in-memory DuckDB instance. Key changes: - Add EngineDuckDB constant to config (internal/config/config.go) - Implement DuckDB analyzer using go-duckdb driver (internal/engine/duckdb/analyzer/) - Register DuckDB engine in compiler with PostgreSQL parser/catalog (internal/compiler/engine.go) - Add DuckDB support to vet command (internal/cmd/vet.go) - Add go-duckdb v1.8.5 dependency (go.mod) - Create comprehensive example with schema, queries, and documentation (examples/duckdb/) The DuckDB implementation leverages PostgreSQL-compatible SQL syntax while providing accurate type inference through live database analysis. The analyzer uses an in-memory DuckDB instance to extract column and parameter types. Features: - PostgreSQL-compatible SQL parsing - In-memory database analysis - Schema migration support - Type-safe Go code generation - Thread-safe connection management 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Fixed DuckDB analyzer to work with database/sql limitations: - Removed incorrect ps.Size() call (ParamSet doesn't have this method) - Parameter types are inferred by catalog-based compiler instead - database/sql doesn't expose parameter type information like pgx does Updated dependencies: - Resolved go-duckdb v1.8.5 and all transitive dependencies - Updated go.mod and go.sum with complete dependency tree Verified build: - internal/engine/duckdb/analyzer builds successfully - cmd/sqlc builds successfully with DuckDB support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Adds a test to verify that: - DuckDB engine can be instantiated via NewCompiler - PostgreSQL catalog is properly initialized - Default schema is set to 'public' as expected Test confirms DuckDB engine integration is working correctly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add sqlc binary and *.test files to gitignore to prevent accidentally committing build artifacts to the repository. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Changes: - Remove unit test from internal/engine/duckdb/duckdb_test.go - Generate expected output for examples/duckdb/ (endtoend test will use this) - Update sqlc.yaml to work without analyzer (catalog-based mode) - Add generated Go code (db.go, models.go, query.sql.go) The DuckDB example will now be tested automatically by TestExamples in internal/endtoend/endtoend_test.go when running with --tags=examples. Note: Analyzer disabled for now as database/sql can't execute parameterized queries without values. Catalog-based type inference works correctly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Creates internal/endtoend/testdata/duckdb_basic/duckdb/ with: - schema.sql: Basic authors table - query.sql: CRUD operations (GetAuthor, ListAuthors, CreateAuthor, DeleteAuthor) - sqlc.yaml: DuckDB engine configuration - go/: Expected generated output (db.go, models.go, query.sql.go) Test automatically discovered by TestReplay and passes: ✅ TestReplay/base/duckdb_basic/duckdb (0.01s) This follows the project's endtoend testing conventions where tests live in internal/endtoend/testdata/ rather than just examples/. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
DuckDB requires CGO (via go-duckdb C bindings), but CI builds with CGO_ENABLED=0. This commit adds proper build constraints to ensure sqlc builds successfully with or without CGO. Changes: - Move go-duckdb import to separate files with //go:build cgo constraint - internal/cmd/vet_duckdb.go: DuckDB driver import (only with CGO) - internal/engine/duckdb/analyzer/driver.go: DuckDB driver import (only with CGO) - Remove go-duckdb import from main vet.go and analyze.go files Build verification: ✅ CGO_ENABLED=1: Full DuckDB support, 121MB binary ✅ CGO_ENABLED=0: DuckDB excluded, 73MB binary (48MB smaller) ✅ Tests pass with CGO enabled ✅ Build succeeds with CGO disabled (CI requirement) The cgo build tag automatically excludes these files when CGO is disabled, allowing sqlc to build on all platforms while providing DuckDB support when CGO is available. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.