@@ -21,15 +21,22 @@ import (
2121 pb "github.com/sqlc-dev/sqlc/pkg/engine"
2222)
2323
24+ // dialectConfig holds dialect options. Plugin API no longer provides these; we use defaults.
25+ type dialectConfig struct {
26+ QuoteChar string
27+ ParamStyle string
28+ ParamPrefix string
29+ CastSyntax string
30+ }
31+
2432// ProcessRunner runs an engine plugin as an external process.
2533type ProcessRunner struct {
2634 Cmd string
2735 Dir string // Working directory for the plugin (config file directory)
2836 Env []string
2937
30- // Cached responses
31- commentSyntax * pb.GetCommentSyntaxResponse
32- dialect * pb.GetDialectResponse
38+ // Default dialect when plugin does not expose GetDialect (new API has only Parse)
39+ dialect * dialectConfig
3340}
3441
3542// NewProcessRunner creates a new ProcessRunner.
@@ -87,6 +94,9 @@ func (r *ProcessRunner) invoke(ctx context.Context, method string, req, resp pro
8794}
8895
8996// Parse implements engine.Parser.
97+ // The plugin returns Sql, Parameters, and Columns (no AST). We produce a single
98+ // synthetic statement so the rest of the pipeline can run; downstream may need
99+ // to use plugin output directly for codegen when that path exists.
90100func (r * ProcessRunner ) Parse (reader io.Reader ) ([]ast.Statement , error ) {
91101 sql , err := io .ReadAll (reader )
92102 if err != nil {
@@ -100,73 +110,49 @@ func (r *ProcessRunner) Parse(reader io.Reader) ([]ast.Statement, error) {
100110 return nil , err
101111 }
102112
103- var stmts []ast.Statement
104- for _ , s := range resp .Statements {
105- // Parse the AST JSON into an ast.Node
106- node , err := parseASTJSON (s .AstJson )
107- if err != nil {
108- return nil , fmt .Errorf ("failed to parse AST: %w" , err )
109- }
110-
111- stmts = append (stmts , ast.Statement {
113+ // New API: resp has Sql, Parameters, Columns (no Statements/AST).
114+ // Return one synthetic statement so callers that expect []ast.Statement still compile.
115+ sqlText := resp .Sql
116+ if sqlText == "" {
117+ sqlText = string (sql )
118+ }
119+ return []ast.Statement {
120+ {
112121 Raw : & ast.RawStmt {
113- Stmt : node ,
114- StmtLocation : int ( s . StmtLocation ) ,
115- StmtLen : int ( s . StmtLen ),
122+ Stmt : & ast. TODO {} ,
123+ StmtLocation : 0 ,
124+ StmtLen : len ( sqlText ),
116125 },
117- })
118- }
119-
120- return stmts , nil
126+ },
127+ }, nil
121128}
122129
123130// CommentSyntax implements engine.Parser.
131+ // Plugin API no longer has GetCommentSyntax; use common defaults.
124132func (r * ProcessRunner ) CommentSyntax () source.CommentSyntax {
125- if r .commentSyntax == nil {
126- req := & pb.GetCommentSyntaxRequest {}
127- resp := & pb.GetCommentSyntaxResponse {}
128- if err := r .invoke (context .Background (), "get_comment_syntax" , req , resp ); err != nil {
129- // Default to common SQL comment syntax
130- return source.CommentSyntax {
131- Dash : true ,
132- SlashStar : true ,
133- }
134- }
135- r .commentSyntax = resp
136- }
137-
138133 return source.CommentSyntax {
139- Dash : r . commentSyntax . Dash ,
140- SlashStar : r . commentSyntax . SlashStar ,
141- Hash : r . commentSyntax . Hash ,
134+ Dash : true ,
135+ SlashStar : true ,
136+ Hash : false ,
142137 }
143138}
144139
145140// IsReservedKeyword implements engine.Parser.
146- func (r * ProcessRunner ) IsReservedKeyword (s string ) bool {
147- req := & pb.IsReservedKeywordRequest {Keyword : s }
148- resp := & pb.IsReservedKeywordResponse {}
149- if err := r .invoke (context .Background (), "is_reserved_keyword" , req , resp ); err != nil {
150- return false
151- }
152- return resp .IsReserved
141+ // Plugin API no longer has IsReservedKeyword; assume not reserved.
142+ func (r * ProcessRunner ) IsReservedKeyword (string ) bool {
143+ return false
153144}
154145
155146// GetCatalog returns the initial catalog for this engine.
147+ // Plugin API no longer has GetCatalog; return an empty catalog.
156148func (r * ProcessRunner ) GetCatalog () (* catalog.Catalog , error ) {
157- req := & pb.GetCatalogRequest {}
158- resp := & pb.GetCatalogResponse {}
159- if err := r .invoke (context .Background (), "get_catalog" , req , resp ); err != nil {
160- return nil , err
161- }
162-
163- return convertCatalog (resp .Catalog ), nil
149+ return catalog .New ("" ), nil
164150}
165151
166152// QuoteIdent implements engine.Dialect.
167153func (r * ProcessRunner ) QuoteIdent (s string ) string {
168154 r .ensureDialect ()
169- if r .IsReservedKeyword ( s ) && r . dialect .QuoteChar != "" {
155+ if r .dialect .QuoteChar != "" {
170156 return r .dialect .QuoteChar + s + r .dialect .QuoteChar
171157 }
172158 return s
@@ -217,107 +203,13 @@ func (r *ProcessRunner) Cast(arg, typeName string) string {
217203
218204func (r * ProcessRunner ) ensureDialect () {
219205 if r .dialect == nil {
220- req := & pb.GetDialectRequest {}
221- resp := & pb.GetDialectResponse {}
222- if err := r .invoke (context .Background (), "get_dialect" , req , resp ); err != nil {
223- // Use defaults
224- r .dialect = & pb.GetDialectResponse {
225- QuoteChar : `"` ,
226- ParamStyle : "dollar" ,
227- ParamPrefix : "@" ,
228- CastSyntax : "cast_function" ,
229- }
230- } else {
231- r .dialect = resp
232- }
233- }
234- }
235-
236- // convertCatalog converts a protobuf Catalog to catalog.Catalog.
237- func convertCatalog (c * pb.Catalog ) * catalog.Catalog {
238- if c == nil {
239- return catalog .New ("" )
240- }
241-
242- cat := catalog .New (c .DefaultSchema )
243- cat .Name = c .Name
244- cat .Comment = c .Comment
245-
246- // Clear default schemas and add from plugin
247- cat .Schemas = make ([]* catalog.Schema , 0 , len (c .Schemas ))
248- for _ , s := range c .Schemas {
249- schema := & catalog.Schema {
250- Name : s .Name ,
251- Comment : s .Comment ,
252- }
253-
254- for _ , t := range s .Tables {
255- table := & catalog.Table {
256- Rel : & ast.TableName {
257- Catalog : t .Catalog ,
258- Schema : t .Schema ,
259- Name : t .Name ,
260- },
261- Comment : t .Comment ,
262- }
263- for _ , col := range t .Columns {
264- table .Columns = append (table .Columns , & catalog.Column {
265- Name : col .Name ,
266- Type : ast.TypeName {Name : col .DataType },
267- IsNotNull : col .NotNull ,
268- IsArray : col .IsArray ,
269- ArrayDims : int (col .ArrayDims ),
270- Comment : col .Comment ,
271- Length : toPointer (int (col .Length )),
272- IsUnsigned : col .IsUnsigned ,
273- })
274- }
275- schema .Tables = append (schema .Tables , table )
276- }
277-
278- for _ , e := range s .Enums {
279- enum := & catalog.Enum {
280- Name : e .Name ,
281- Comment : e .Comment ,
282- }
283- enum .Vals = append (enum .Vals , e .Values ... )
284- schema .Types = append (schema .Types , enum )
285- }
286-
287- for _ , f := range s .Functions {
288- fn := & catalog.Function {
289- Name : f .Name ,
290- Comment : f .Comment ,
291- ReturnType : & ast.TypeName {Schema : f .ReturnType .GetSchema (), Name : f .ReturnType .GetName ()},
292- }
293- for _ , arg := range f .Args {
294- fn .Args = append (fn .Args , & catalog.Argument {
295- Name : arg .Name ,
296- Type : & ast.TypeName {Schema : arg .Type .GetSchema (), Name : arg .Type .GetName ()},
297- HasDefault : arg .HasDefault ,
298- })
299- }
300- schema .Funcs = append (schema .Funcs , fn )
301- }
302-
303- for _ , t := range s .Types {
304- schema .Types = append (schema .Types , & catalog.CompositeType {
305- Name : t .Name ,
306- Comment : t .Comment ,
307- })
206+ r .dialect = & dialectConfig {
207+ QuoteChar : `"` ,
208+ ParamStyle : "dollar" ,
209+ ParamPrefix : "@" ,
210+ CastSyntax : "cast_function" ,
308211 }
309-
310- cat .Schemas = append (cat .Schemas , schema )
311- }
312-
313- return cat
314- }
315-
316- func toPointer (n int ) * int {
317- if n == 0 {
318- return nil
319212 }
320- return & n
321213}
322214
323215// parseASTJSON parses AST JSON into an ast.Node.
0 commit comments