Added support for the database engine plugin system for extending sqlc with new databases (in addition to PostgreSQL, Dolphin, sqlite) #4247
+6,199
−13
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.
This PR resolve issue #4158
Database Engine Plugins
sqlc supports adding custom database backends through engine plugins. This allows you to use sqlc with databases that aren't natively supported (like MyDB, CockroachDB, or other SQL-compatible databases).
Overview
Engine plugins are external programs that implement the sqlc engine interface:
Compatibility Guarantee
For Go process plugins, compatibility is guaranteed at compile time:
When you import this package:
The Protocol Buffer schema ensures binary compatibility. No version negotiation needed.
Configuration
sqlc.yaml
Configuration Options
namesql[].engine)process.cmdwasm.urlfile://orhttps://)wasm.sha256envCreating a Go Engine Plugin
1. Import the SDK
2. Implement the Handler
3. Implement Methods
Parse
Parses SQL text into statements with AST.
GetCatalog
Returns the initial catalog with built-in types and functions.
IsReservedKeyword
Checks if a string is a reserved keyword.
GetCommentSyntax
Returns supported SQL comment syntax.
GetDialect
Returns SQL dialect information for formatting.
4. Build and Install
go build -o sqlc-engine-mydb . mv sqlc-engine-mydb /usr/local/bin/Protocol
Process Plugins (Go)
Process plugins use Protocol Buffers for serialization:
The proto schema is published at
buf.build/sqlc/sqlcinengine/engine.proto.Methods are invoked as command-line arguments:
WASM Plugins
WASM plugins use JSON for broader language compatibility:
Full Example
See
examples/plugin-based-codegen/for a complete engine plugin implementation.Architecture