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
.gitignore + README
  • Loading branch information
asmyasnikov committed Jan 10, 2026
commit 7609ebcc3505483176224307467abb3399b9064d
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ __pycache__
.devenv*
devenv.local.nix

/bin/sqlc
Comment thread
asmyasnikov marked this conversation as resolved.
Outdated
130 changes: 130 additions & 0 deletions examples/plugin-based-codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ SQLCDEBUG=processplugins=1 sqlc generate

## How It Works

### Architecture Flow

```
┌─────────────────────────────────────────────────────────────────┐
│ sqlc generate │
│ │
│ 1. Read schema.sql & queries.sql │
│ 2. Send SQL to engine plugin (sqlc-engine-*) │
│ └─> Parse SQL, return AST & Catalog │
│ 3. Analyze queries with AST & Catalog │
│ 4. Send queries + catalog to codegen plugin (sqlc-gen-*) │
│ └─> Generate code (Rust, Go, etc.) │
│ 5. Write generated files │
└─────────────────────────────────────────────────────────────────┘
```

### Database Engine Plugin (`sqlc-engine-sqlite3`)

The engine plugin implements the `pkg/engine.Handler` interface:
Expand Down Expand Up @@ -98,6 +114,62 @@ func main() {

Communication: **Protobuf over stdin/stdout**

### Parameter Passing: `sql_package` Example

For Go code generation, the `sql_package` parameter is passed to the codegen plugin:

```
┌─────────────────────────────────────────────────────────────────┐
│ sqlc.yaml │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ gen: │ │
│ │ go: │ │
│ │ sql_package: "database/sql" # or "pgx/v5" │ │
│ └───────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ GenerateRequest (protobuf) │ │
│ │ Settings: │ │
│ │ Codegen: │ │
│ │ Options: []byte{ │ │
│ │ "sql_package": "database/sql", # JSON │ │
│ │ "package": "db", │ │
│ │ ... │ │
│ │ } │ │
│ │ Queries: [...] │ │
│ │ Catalog: {...} │ │
│ └───────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ Codegen Plugin (sqlc-gen-go or custom) │ │
│ │ func generate(req *plugin.GenerateRequest) { │ │
│ │ var opts Options │ │
│ │ json.Unmarshal(req.PluginOptions, &opts) │ │
│ │ // opts.SqlPackage == "database/sql" │ │
│ │ // Generate code using database/sql APIs │ │
│ │ } │ │
│ └───────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
```

**Important Notes:**

1. **Standard Go codegen** (`gen.go`) only supports:
- `database/sql` (stdlib)
- `pgx/v4` (PostgreSQL)
- `pgx/v5` (PostgreSQL)

2. **Custom SQL packages** (e.g., `github.com/ydb-platform/ydb-go-sdk/v3`) require:
- A **custom codegen plugin** that reads `sql_package` from `PluginOptions`
- The plugin generates code using the specified package's APIs

3. **Example**: For YDB native SDK, you would create `sqlc-gen-ydb-go` that:
- Reads `sql_package: "github.com/ydb-platform/ydb-go-sdk/v3"` from options
- Generates code using `ydb.Session` instead of `*sql.DB`
- Uses YDB-specific APIs for query execution

## Compatibility

Both plugins import public packages from sqlc:
Expand Down Expand Up @@ -177,6 +249,64 @@ pub async fn create_user(pool: &SqlitePool, id: i32, name: String, email: String
}
```

## Example: Go Codegen with Custom `sql_package`

For Go code generation, the standard `gen.go` only supports `database/sql`, `pgx/v4`, and `pgx/v5`. To use other SQL packages (e.g., `github.com/ydb-platform/ydb-go-sdk/v3`), you need a custom codegen plugin.

**Example: `sqlc-gen-ydb-go` plugin**

```go
package main

import (
"encoding/json"
"github.com/sqlc-dev/sqlc/pkg/plugin"
)

type Options struct {
Package string `json:"package"`
SqlPackage string `json:"sql_package"` // e.g., "github.com/ydb-platform/ydb-go-sdk/v3"
Out string `json:"out"`
}

func generate(req *plugin.GenerateRequest) (*plugin.GenerateResponse, error) {
var opts Options
json.Unmarshal(req.PluginOptions, &opts)

// opts.SqlPackage contains the value from sqlc.yaml
// Generate code using the specified package's APIs
if opts.SqlPackage == "github.com/ydb-platform/ydb-go-sdk/v3" {
// Generate YDB-specific code using ydb.Session
} else {
// Generate standard database/sql code
}

return &plugin.GenerateResponse{
Files: []*plugin.File{...},
}, nil
}
```

**Configuration:**

```yaml
plugins:
- name: ydb-go
process:
cmd: sqlc-gen-ydb-go

sql:
- engine: ydb
schema: "schema.sql"
queries: "queries.sql"
codegen:
- plugin: ydb-go
out: db
options:
sql_package: "github.com/ydb-platform/ydb-go-sdk/v3"
package: "db"
```

## See Also

- [Engine Plugins Documentation](../../docs/howto/engine-plugins.md)
Expand Down
Loading