Skip to content

Commit

Permalink
Fix Upsert Statements With External Ids
Browse files Browse the repository at this point in the history
Fix formatting of upsert statements containing external ids.
  • Loading branch information
cwarden committed Mar 7, 2024
1 parent 9546f21 commit 4df11fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions formatter/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ Name = 'My Opportunity',
{
`Error__c[] errorLogs = new Error__c[0];`,
`Error__c[] errorLogs = new Error__c[0];`},
{
`upsert myAccount External_Id__c;`,
`upsert myAccount External_Id__c;`},
}
for _, tt := range tests {
input := antlr.NewInputStream(tt.input)
Expand Down
6 changes: 5 additions & 1 deletion formatter/visitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,11 @@ func (v *FormatVisitor) VisitUpdateStatement(ctx *parser.UpdateStatementContext)
}

func (v *FormatVisitor) VisitUpsertStatement(ctx *parser.UpsertStatementContext) interface{} {
return fmt.Sprintf("upsert %s;", v.visitRule(ctx.Expression()))
if q := ctx.QualifiedName(); q != nil {
return fmt.Sprintf("upsert %s %s;", v.visitRule(ctx.Expression()), v.visitRule(q))
} else {
return fmt.Sprintf("upsert %s;", v.visitRule(ctx.Expression()))
}
}

func (v *FormatVisitor) VisitMergeStatement(ctx *parser.MergeStatementContext) interface{} {
Expand Down

0 comments on commit 4df11fd

Please sign in to comment.