Skip to content

Commit 217ed0a

Browse files
committed
feat: add PGLite-based PostgreSQL analyzer using wazero
Add experimental support for PGLite, an embedded PostgreSQL that runs in WebAssembly via wazero. This allows database-backed type analysis without requiring a running PostgreSQL server. Changes: - Add 'pglite' experiment flag (SQLCEXPERIMENT=pglite) - Add PGLite configuration in analyzer config (url, sha256) - Create pglite analyzer package that uses wazero runtime - Wire PGLite analyzer into compiler when experiment is enabled To use PGLite analyzer, enable the experiment and configure it: SQLCEXPERIMENT=pglite sqlc generate sqlc.yaml: sql: - engine: postgresql analyzer: pglite: url: "file://path/to/pglite.wasm" sha256: "..." 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 74ecda5 commit 217ed0a

File tree

6 files changed

+968
-3
lines changed

6 files changed

+968
-3
lines changed

internal/compiler/engine.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/sqlc-dev/sqlc/internal/engine/dolphin"
1111
"github.com/sqlc-dev/sqlc/internal/engine/postgresql"
1212
pganalyze "github.com/sqlc-dev/sqlc/internal/engine/postgresql/analyzer"
13+
"github.com/sqlc-dev/sqlc/internal/engine/postgresql/pglite"
1314
"github.com/sqlc-dev/sqlc/internal/engine/sqlite"
1415
sqliteanalyze "github.com/sqlc-dev/sqlc/internal/engine/sqlite/analyzer"
1516
"github.com/sqlc-dev/sqlc/internal/opts"
@@ -59,7 +60,12 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err
5960
c.parser = postgresql.NewParser()
6061
c.catalog = postgresql.NewCatalog()
6162
c.selector = newDefaultSelector()
62-
if conf.Database != nil {
63+
64+
// Check if PGLite analyzer is configured and experiment is enabled
65+
exp := opts.ExperimentFromEnv()
66+
if exp.PGLite && conf.Analyzer.PGLite != nil {
67+
c.analyzer = pglite.New(*conf.Analyzer.PGLite)
68+
} else if conf.Database != nil {
6369
if conf.Analyzer.Database == nil || *conf.Analyzer.Database {
6470
c.analyzer = analyzer.Cached(
6571
pganalyze.New(c.client, *conf.Database),

internal/config/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ type SQL struct {
123123
}
124124

125125
type Analyzer struct {
126-
Database *bool `json:"database" yaml:"database"`
126+
Database *bool `json:"database" yaml:"database"`
127+
PGLite *PGLite `json:"pglite" yaml:"pglite"`
128+
}
129+
130+
type PGLite struct {
131+
URL string `json:"url" yaml:"url"`
132+
SHA256 string `json:"sha256" yaml:"sha256"`
127133
}
128134

129135
// TODO: Figure out a better name for this

0 commit comments

Comments
 (0)