66 "github.com/efritz/gostgres/internal/catalog"
77 "github.com/efritz/gostgres/internal/catalog/aggregates"
88 "github.com/efritz/gostgres/internal/catalog/functions"
9- "github.com/efritz/gostgres/internal/execution/engine/ protocol"
9+ "github.com/efritz/gostgres/internal/execution/protocol"
1010 "github.com/efritz/gostgres/internal/shared/impls"
1111 "github.com/efritz/gostgres/internal/shared/rows"
1212 "github.com/efritz/gostgres/internal/syntax/lexing"
@@ -43,10 +43,11 @@ func NewEngine(
4343 }
4444}
4545
46- func (e * Engine ) Query (input string , debug bool ) (rows. Rows , error ) {
47- query , err := parsing .Parse (lexing .Lex (input ), e .tables )
46+ func (e * Engine ) Query (request protocol. Request , responseWriter protocol. ResponseWriter ) {
47+ query , err := parsing .Parse (lexing .Lex (request . Query ), e .tables )
4848 if err != nil {
49- return rows.Rows {}, fmt .Errorf ("failed to parse query: %s" , err )
49+ responseWriter .Error (fmt .Errorf ("failed to parse query: %s" , err ))
50+ return
5051 }
5152
5253 ctx := impls .NewContext (
@@ -55,16 +56,27 @@ func (e *Engine) Query(input string, debug bool) (rows.Rows, error) {
5556 e .functions ,
5657 e .aggregates ,
5758 )
58- if debug {
59+ if request . Debug {
5960 ctx = ctx .WithDebug ()
6061 }
6162
63+ query .Execute (ctx , responseWriter )
64+ }
65+
66+ func (e * Engine ) QueryRows (request protocol.Request ) (rows.Rows , error ) {
6267 collector := protocol .NewRowCollector ()
63- query . Execute ( ctx , collector )
68+ e . Query ( request , collector )
6469 collectedRows , err := collector .Rows ()
6570 if err != nil {
66- return rows.Rows {}, fmt .Errorf ("failed to execute query %q: %s" , input , err )
71+ return rows.Rows {}, fmt .Errorf ("failed to execute query %q: %s" , request . Query , err )
6772 }
6873
6974 return collectedRows , nil
7075}
76+
77+ func (e * Engine ) QueryError (request protocol.Request ) error {
78+ collector := protocol .NewRowCollector ()
79+ e .Query (request , collector )
80+ _ , err := collector .Rows ()
81+ return err
82+ }
0 commit comments