Skip to content

Conversation

@kyleconroy
Copy link
Collaborator

No description provided.

This commit adds comprehensive DuckDB support to sqlc using a
database-backed approach with required analyzer, similar to PostgreSQL's
optional analyzer pattern but made mandatory for DuckDB.

Key features:
- Database-backed catalog using DuckDB connections
- Required analyzer for type inference and schema information
- TiDB parser for SQL parsing (shared with MySQL engine)
- DuckDB reserved keywords implementation
- Type normalization for DuckDB-specific types
- Example project demonstrating basic usage

Implementation details:
- Parser: Uses TiDB parser, supports -- and /* */ comments
- Catalog: Minimal implementation, no pre-generated types
- Analyzer: Required component, connects via go-duckdb driver
- Converter: Reuses Dolphin/MySQL AST converter
- Reserved keywords: Based on DuckDB 1.3.0 specification

Files created:
- internal/engine/duckdb/parse.go - Parser implementation
- internal/engine/duckdb/catalog.go - Minimal catalog
- internal/engine/duckdb/convert.go - AST converter
- internal/engine/duckdb/reserved.go - Reserved keywords
- internal/engine/duckdb/analyzer/analyze.go - Database analyzer
- examples/duckdb/basic/ - Example project
- DUCKDB_SUPPORT.md - Comprehensive documentation

Files modified:
- internal/config/config.go - Added EngineDuckDB constant
- internal/compiler/engine.go - Registered DuckDB with analyzer
- go.mod - Added github.com/marcboeker/go-duckdb v1.8.5

Requirements:
- Database connection is required (not optional)
- Configuration must include database.uri parameter
- Run 'go mod tidy' to download dependencies (network required)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
… only

DuckDB now uses a minimal pass-through parser instead of the TiDB parser.
All SQL parsing, validation, and type checking happens directly in the
DuckDB database via the analyzer. This ensures 100% compatibility with
DuckDB syntax without maintaining a separate parser.

Changes:
- Removed TiDB parser dependency from parse.go
- Parser now returns minimal TODO AST nodes
- Deleted convert.go (AST conversion not needed)
- Database handles all SQL validation via PREPARE/DESCRIBE
- Updated documentation to reflect database-only validation approach

Benefits:
- No shared parser with MySQL/Dolphin engine
- Perfect DuckDB syntax compatibility
- Simpler codebase with fewer dependencies
- All validation happens where it should: in the database

The analyzer is now solely responsible for:
- Parsing SQL via DuckDB's native parser
- Validating queries against the schema
- Extracting column and parameter type information
- Normalizing DuckDB types to sqlc types

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. 🔧 golang labels Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files. 🔧 golang

3 participants