Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b6aa62d
Added support for the database engine plugin system for extending sql…
asmyasnikov Dec 28, 2025
5336821
Fix of endtoend tests
asmyasnikov Dec 28, 2025
2b88994
added install plugin-based-codegen's
asmyasnikov Dec 28, 2025
b1d156d
remove tmp file
asmyasnikov Dec 28, 2025
9f65d4f
removed go.{mod,sum}
asmyasnikov Dec 28, 2025
74b621f
SQLCDEBUG=processplugins=1
asmyasnikov Dec 28, 2025
cede5d3
Fix
asmyasnikov Dec 28, 2025
15b240d
Fix
asmyasnikov Dec 28, 2025
0b3b165
Apply suggestions from code review
asmyasnikov Dec 28, 2025
6c5b9a6
revert Combine
asmyasnikov Dec 28, 2025
7609ebc
.gitignore + README
asmyasnikov Jan 10, 2026
2c74313
simplified engine API
asmyasnikov Jan 27, 2026
88e6082
Apply suggestions from code review
asmyasnikov Jan 27, 2026
f39ae4a
Delete protos/engine/engine_grpc.pb.go
asmyasnikov Jan 27, 2026
18f5368
Delete protos/engine/engine.pb.go
asmyasnikov Jan 27, 2026
8eaef3c
Delete pkg/plugin/sdk.go
asmyasnikov Jan 27, 2026
fbaf6ba
Delete pkg/engine/engine.pb.go
asmyasnikov Jan 27, 2026
ce385ae
Delete pkg/plugin/codegen.pb.go
asmyasnikov Jan 27, 2026
a024d3e
Delete examples/plugin-based-codegen/README.md
asmyasnikov Jan 27, 2026
fbd5b43
Delete examples/plugin-based-codegen/gen/rust/queries.rs
asmyasnikov Jan 27, 2026
e6a730a
docs
asmyasnikov Jan 27, 2026
c8831c7
removed example
asmyasnikov Jan 27, 2026
6d5770f
fix
asmyasnikov Jan 27, 2026
d2417e8
Update .gitignore
asmyasnikov Jan 27, 2026
c50e9c7
pb.go
asmyasnikov Jan 27, 2026
e9cc264
fix comments
asmyasnikov Jan 27, 2026
ad7bf6c
simplified plugin engine code
asmyasnikov Jan 27, 2026
5d4c8dd
sourceFiles
asmyasnikov Jan 27, 2026
131d7bb
fix
asmyasnikov Jan 27, 2026
048a64d
Apply suggestions from code review
asmyasnikov Jan 27, 2026
79621b0
removed temp file
asmyasnikov Jan 27, 2026
d9df83b
Apply suggestions from code review
asmyasnikov Jan 27, 2026
55760fc
Apply suggestions from code review
asmyasnikov Jan 27, 2026
96dfabd
Apply suggestions from code review
asmyasnikov Jan 27, 2026
85475e2
removed engine interface
asmyasnikov Jan 27, 2026
0f81f5d
merge files
asmyasnikov Jan 27, 2026
7800a42
move md doc
asmyasnikov Jan 27, 2026
f6b34f0
Apply suggestions from code review
asmyasnikov Jan 27, 2026
830767e
revert changes
asmyasnikov Jan 27, 2026
e4667d2
revert
asmyasnikov Jan 27, 2026
9b9b3ed
docs
asmyasnikov Jan 27, 2026
a8fec25
fix
asmyasnikov Jan 27, 2026
778b45c
fixes and tests
asmyasnikov Jan 28, 2026
fb7e9a6
change ParseResponse - returns multiple statements from single call
asmyasnikov Jan 28, 2026
13fc9f3
Merge branch 'sqlc-dev:main' into engine-plugin
asmyasnikov Jan 30, 2026
12ffdbb
fix
asmyasnikov Feb 1, 2026
2e280c8
Merge branch 'sqlc-dev:main' into engine-plugin
asmyasnikov Feb 5, 2026
a6a4bdb
fix doc
asmyasnikov Feb 8, 2026
2f48010
fix doc
asmyasnikov Feb 8, 2026
bd1f56e
throw error on wrong external plugin options
asmyasnikov Feb 8, 2026
d4ccb4d
Catalog from engine plugin
asmyasnikov Feb 9, 2026
b9d8139
clickhouse + YDB
asmyasnikov Feb 13, 2026
ec0503c
README
asmyasnikov Feb 13, 2026
7f8f44e
Merge branch 'sqlc-dev:main' into engine-plugin
asmyasnikov Feb 21, 2026
eedd52c
Merge branch 'sqlc-dev:main' into engine-plugin
asmyasnikov Feb 25, 2026
7b46024
Merge branch 'sqlc-dev:main' into engine-plugin
asmyasnikov Mar 23, 2026
6b8773a
use EngineService over process.Runner
asmyasnikov Apr 13, 2026
325b16d
Merge branch 'sqlc-dev:main' into engine-plugin
asmyasnikov Apr 23, 2026
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
Prev Previous commit
Next Next commit
Fix of endtoend tests
  • Loading branch information
asmyasnikov committed Jan 10, 2026
commit 53368215622d756cd3dab6752224d50569e263b3
1 change: 1 addition & 0 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql OutputPair,
case plug.Process != nil:
handler = &process.Runner{
Cmd: plug.Process.Cmd,
Dir: combo.Dir,
Env: plug.Env,
Format: plug.Process.Format,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func processQuerySets(ctx context.Context, rp ResultProcessor, conf *config.Conf
errout := &stderrs[i]

grp.Go(func() error {
combo := config.Combine(*conf, sql.SQL)
combo := config.Combine(*conf, sql.SQL, dir)
if sql.Plugin != nil {
combo.Codegen = *sql.Plugin
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/vet.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (c *checker) DSN(dsn string) (string, error) {

func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
// TODO: Create a separate function for this logic so we can
combo := config.Combine(*c.Conf, s)
combo := config.Combine(*c.Conf, s, c.Dir)

// TODO: This feels like a hack that will bite us later
joined := make([]string, 0, len(s.Schema))
Expand Down
6 changes: 3 additions & 3 deletions internal/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings, parserOpts opts
default:
// Check if this is a plugin engine
if enginePlugin, found := config.FindEnginePlugin(&combo.Global, string(conf.Engine)); found {
eng, err := createPluginEngine(enginePlugin)
eng, err := createPluginEngine(enginePlugin, combo.Dir)
if err != nil {
return nil, err
}
Expand All @@ -137,10 +137,10 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings, parserOpts opts
}

// createPluginEngine creates an engine from an engine plugin configuration.
func createPluginEngine(ep *config.EnginePlugin) (engine.Engine, error) {
func createPluginEngine(ep *config.EnginePlugin, dir string) (engine.Engine, error) {
switch {
case ep.Process != nil:
return plugin.NewPluginEngine(ep.Name, ep.Process.Cmd, ep.Env), nil
return plugin.NewPluginEngine(ep.Name, ep.Process.Cmd, dir, ep.Env), nil
case ep.WASM != nil:
return plugin.NewWASMPluginEngine(ep.Name, ep.WASM.URL, ep.WASM.SHA256, ep.Env), nil
default:
Expand Down
6 changes: 5 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,16 @@ type CombinedSettings struct {

// TODO: Combine these into a more usable type
Codegen Codegen

// Dir is the directory containing the config file (for resolving relative paths)
Dir string
}

func Combine(conf Config, pkg SQL) CombinedSettings {
func Combine(conf Config, pkg SQL, dir string) CombinedSettings {
cs := CombinedSettings{
Global: conf,
Package: pkg,
Dir: dir,
}
if pkg.Gen.Go != nil {
cs.Go = *pkg.Gen.Go
Expand Down
12 changes: 8 additions & 4 deletions internal/endtoend/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func TestExamples(t *testing.T) {
t.Parallel()
path := filepath.Join(examples, tc)
var stderr bytes.Buffer
opts := &cmd.Options{
Env: cmd.Env{},
o := &cmd.Options{
Env: cmd.Env{Debug: opts.DebugFromString("")},
Comment thread
asmyasnikov marked this conversation as resolved.
Outdated
Stderr: &stderr,
}
output, err := cmd.Generate(ctx, path, "", opts)
output, err := cmd.Generate(ctx, path, "", o)
Comment thread
asmyasnikov marked this conversation as resolved.
Outdated
if err != nil {
t.Fatalf("sqlc generate failed: %s", stderr.String())
}
Expand Down Expand Up @@ -311,7 +311,7 @@ func cmpDirectory(t *testing.T, dir string, actual map[string]string) {
if file.IsDir() {
return nil
}
if !strings.HasSuffix(path, ".go") && !strings.HasSuffix(path, ".kt") && !strings.HasSuffix(path, ".py") && !strings.HasSuffix(path, ".json") && !strings.HasSuffix(path, ".txt") {
if !strings.HasSuffix(path, ".go") && !strings.HasSuffix(path, ".kt") && !strings.HasSuffix(path, ".py") && !strings.HasSuffix(path, ".json") && !strings.HasSuffix(path, ".txt") && !strings.HasSuffix(path, ".rs") {
Comment thread
asmyasnikov marked this conversation as resolved.
Outdated
return nil
}
// TODO: Figure out a better way to ignore certain files
Expand All @@ -330,6 +330,10 @@ func cmpDirectory(t *testing.T, dir string, actual map[string]string) {
if strings.HasSuffix(path, "_test.go") || strings.Contains(path, "src/test/") {
return nil
}
// Skip plugin source files - they are not generated by sqlc
if strings.Contains(path, "/plugins/") {
return nil
}
Comment thread
asmyasnikov marked this conversation as resolved.
Outdated
if strings.Contains(path, "/python/.venv") || strings.Contains(path, "/python/src/tests/") ||
strings.HasSuffix(path, "__init__.py") || strings.Contains(path, "/python/src/dbtest/") ||
strings.Contains(path, "/python/.mypy_cache") {
Expand Down
12 changes: 9 additions & 3 deletions internal/engine/plugin/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
// ProcessRunner runs an engine plugin as an external process.
type ProcessRunner struct {
Cmd string
Dir string // Working directory for the plugin (config file directory)
Env []string

// Cached responses
Expand All @@ -32,9 +33,10 @@ type ProcessRunner struct {
}

// NewProcessRunner creates a new ProcessRunner.
func NewProcessRunner(cmd string, env []string) *ProcessRunner {
func NewProcessRunner(cmd, dir string, env []string) *ProcessRunner {
return &ProcessRunner{
Cmd: cmd,
Dir: dir,
Env: env,
}
}
Expand All @@ -60,6 +62,10 @@ func (r *ProcessRunner) invoke(ctx context.Context, method string, req, resp pro
args := append(cmdParts[1:], method)
cmd := exec.CommandContext(ctx, path, args...)
cmd.Stdin = bytes.NewReader(stdin)
// Set working directory to config file directory for relative paths
if r.Dir != "" {
cmd.Dir = r.Dir
}
// Inherit the current environment and add SQLC_VERSION
cmd.Env = append(os.Environ(), fmt.Sprintf("SQLC_VERSION=%s", info.Version))

Expand Down Expand Up @@ -446,10 +452,10 @@ type PluginEngine struct {
}

// NewPluginEngine creates a new engine from a process plugin.
func NewPluginEngine(name, cmd string, env []string) *PluginEngine {
func NewPluginEngine(name, cmd, dir string, env []string) *PluginEngine {
return &PluginEngine{
name: name,
runner: NewProcessRunner(cmd, env),
runner: NewProcessRunner(cmd, dir, env),
}
}

Expand Down
5 changes: 5 additions & 0 deletions internal/ext/process/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

type Runner struct {
Cmd string
Dir string // Working directory for the plugin (config file directory)
Format string
Env []string
}
Expand Down Expand Up @@ -70,6 +71,10 @@ func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any,
cmdArgs := append(cmdParts[1:], method)
cmd := exec.CommandContext(ctx, path, cmdArgs...)
cmd.Stdin = bytes.NewReader(stdin)
// Set working directory to config file directory for relative paths
if r.Dir != "" {
cmd.Dir = r.Dir
}
// Inherit the current environment (excluding SQLC_AUTH_TOKEN) and add SQLC_VERSION
for _, env := range os.Environ() {
if !strings.HasPrefix(env, "SQLC_AUTH_TOKEN=") {
Expand Down