-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdml_delete.go
More file actions
38 lines (32 loc) · 1.16 KB
/
dml_delete.go
File metadata and controls
38 lines (32 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// dml_delete.go implements DELETE population logic for the IR builder.
package postgresparser
import (
"fmt"
"github.com/antlr4-go/antlr/v4"
"github.com/valkdb/postgresparser/gen"
)
// populateDelete captures DELETE targets, USING tables, predicates, and returning data.
func populateDelete(result *ParsedQuery, ctx gen.IDeletestmtContext, tokens antlr.TokenStream) error {
if ctx == nil {
return fmt.Errorf("delete statement: %w", ErrNilContext)
}
if ctx.With_clause_() != nil {
if withCtx := ctx.With_clause_().With_clause(); withCtx != nil {
ctes, cteTables := extractCTEs(withCtx, tokens)
result.CTEs = append(result.CTEs, ctes...)
result.Tables = append(result.Tables, cteTables...)
}
}
cteNames := buildCTENameSet(result.CTEs)
appendRelationOptAlias(result, ctx.Relation_expr_opt_alias(), tokens)
if ctx.Using_clause() != nil {
extractFromList(result, ctx.Using_clause().From_list(), tokens, cteNames)
}
if where := ctx.Where_or_current_clause(); where != nil {
if prc, ok := where.(antlr.ParserRuleContext); ok {
appendWhereClause(result, prc, tokens)
}
}
appendReturningClause(result, ctx.Returning_clause(), tokens)
return nil
}