github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/tree/delete.go (about)

     1  // Copyright 2012, Google Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in licenses/BSD-vitess.txt.
     4  
     5  // Portions of this file are additionally subject to the following
     6  // license and copyright.
     7  //
     8  // Copyright 2015 The Cockroach Authors.
     9  //
    10  // Use of this software is governed by the Business Source License
    11  // included in the file licenses/BSL.txt.
    12  //
    13  // As of the Change Date specified in that file, in accordance with
    14  // the Business Source License, use of this software will be governed
    15  // by the Apache License, Version 2.0, included in the file
    16  // licenses/APL.txt.
    17  
    18  // This code was derived from https://github.com/youtube/vitess.
    19  
    20  package tree
    21  
    22  // Delete represents a DELETE statement.
    23  type Delete struct {
    24  	With      *With
    25  	Table     TableExpr
    26  	Where     *Where
    27  	OrderBy   OrderBy
    28  	Limit     *Limit
    29  	Returning ReturningClause
    30  }
    31  
    32  // Format implements the NodeFormatter interface.
    33  func (node *Delete) Format(ctx *FmtCtx) {
    34  	ctx.FormatNode(node.With)
    35  	ctx.WriteString("DELETE FROM ")
    36  	ctx.FormatNode(node.Table)
    37  	if node.Where != nil {
    38  		ctx.WriteByte(' ')
    39  		ctx.FormatNode(node.Where)
    40  	}
    41  	if len(node.OrderBy) > 0 {
    42  		ctx.WriteByte(' ')
    43  		ctx.FormatNode(&node.OrderBy)
    44  	}
    45  	if node.Limit != nil {
    46  		ctx.WriteByte(' ')
    47  		ctx.FormatNode(node.Limit)
    48  	}
    49  	if HasReturningClause(node.Returning) {
    50  		ctx.WriteByte(' ')
    51  		ctx.FormatNode(node.Returning)
    52  	}
    53  }