Skip to content

Commit a8fec25

Browse files
committed
fix
1 parent 9b9b3ed commit a8fec25

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

docs/guides/engine-plugins.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ sql:
6666

6767
Each engine must define either `process` (with `cmd`) or `wasm` (with `url` and `sha256`). See [Configuration reference](../reference/config.md) for the full `engines` schema.
6868

69+
### How sqlc finds the process plugin
70+
71+
For an engine with `process.cmd`, sqlc resolves and runs the plugin as follows:
72+
73+
1. **Command parsing** — `process.cmd` is split on whitespace. The first token is the executable; any further tokens are passed as arguments, and sqlc appends the RPC method name (`parse`) when invoking the plugin.
74+
75+
2. **Executable lookup** — The first token is resolved the same way as in the shell:
76+
- If it contains a path separator (e.g. `/usr/bin/sqlc-engine-mydb` or `./bin/sqlc-engine-mydb`), it is treated as a path. Absolute paths are used as-is; relative paths are taken relative to the **current working directory of the process running sqlc**.
77+
- If it has no path separator, the executable is looked up in the **PATH** of the process running sqlc. The plugin binary must be on PATH (e.g. after `go install` or adding its directory to PATH) or `process.cmd` must be an absolute path.
78+
79+
3. **Working directory** — The plugin process is started with its working directory set to the **directory containing the sqlc config file**. That directory is used for resolving relative paths inside the plugin, not for resolving `process.cmd` itself.
80+
81+
If the executable cannot be found or `process.cmd` is empty, sqlc reports an error and refers to this documentation.
82+
6983
## Implementing an engine plugin (Go)
7084

7185
### 1. Dependencies and entrypoint

internal/cmd/plugin_engine.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ func (r *engineProcessRunner) invoke(ctx context.Context, method string, req, re
4545

4646
cmdParts := strings.Fields(r.Cmd)
4747
if len(cmdParts) == 0 {
48-
return fmt.Errorf("engine plugin not found: %s\n\nMake sure the plugin is installed and available in PATH.\nInstall with: go install <plugin-module>@latest", r.Cmd)
48+
return fmt.Errorf("engine plugin not found: %s\n\nSee the engine plugins documentation: https://docs.sqlc.dev/en/latest/guides/engine-plugins.html", r.Cmd)
4949
}
5050

5151
path, err := exec.LookPath(cmdParts[0])
5252
if err != nil {
53-
return fmt.Errorf("engine plugin not found: %s\n\nMake sure the plugin is installed and available in PATH.\nInstall with: go install <plugin-module>@latest", r.Cmd)
53+
return fmt.Errorf("engine plugin not found: %s\n\nSee the engine plugins documentation: https://docs.sqlc.dev/en/latest/guides/engine-plugins.html", r.Cmd)
5454
}
5555

5656
args := append(cmdParts[1:], method)
@@ -97,8 +97,7 @@ func runPluginQuerySet(ctx context.Context, rp ResultProcessor, name, dir string
9797
enginePlugin, found := config.FindEnginePlugin(&combo.Global, string(combo.Package.Engine))
9898
if !found || enginePlugin.Process == nil {
9999
e := string(combo.Package.Engine)
100-
return fmt.Errorf("unknown engine: %s\n\nTo use a custom database engine, add it to the 'engines' section of sqlc.yaml:\n\n engines:\n - name: %s\n process:\n cmd: sqlc-engine-%s\n\nThen install the plugin: go install github.com/example/sqlc-engine-%s@latest",
101-
e, e, e, e)
100+
return fmt.Errorf("unknown engine: %s\n\nAdd the engine to the 'engines' section of sqlc.yaml. See the engine plugins documentation: https://docs.sqlc.dev/en/latest/guides/engine-plugins.html", e)
102101
}
103102

104103
var parseFn func(schemaSQL, querySQL string) (*pb.ParseResponse, error)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
error creating compiler: unknown engine: bad_engine
1+
error creating compiler: unknown engine: bad_engine
2+
3+
Add the engine to the 'engines' section of sqlc.yaml. See the engine plugins documentation: https://docs.sqlc.dev/en/latest/guides/engine-plugins.html

0 commit comments

Comments
 (0)