github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/parsers/tree/delete.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tree 16 17 // Delete statement 18 type Delete struct { 19 statementImpl 20 Tables TableExprs 21 TableRefs TableExprs 22 PartitionNames IdentifierList 23 Where *Where 24 OrderBy OrderBy 25 Limit *Limit 26 With *With 27 } 28 29 func (node *Delete) Format(ctx *FmtCtx) { 30 if node.With != nil { 31 node.With.Format(ctx) 32 ctx.WriteByte(' ') 33 } 34 ctx.WriteString("delete from ") 35 36 prefix := "" 37 for _, a := range node.Tables { 38 ctx.WriteString(prefix) 39 a.Format(ctx) 40 prefix = ", " 41 } 42 43 if node.PartitionNames != nil { 44 ctx.WriteString(" partition(") 45 node.PartitionNames.Format(ctx) 46 ctx.WriteByte(')') 47 } 48 49 if node.TableRefs != nil { 50 ctx.WriteString(" using ") 51 node.TableRefs.Format(ctx) 52 } 53 54 if node.Where != nil { 55 ctx.WriteByte(' ') 56 node.Where.Format(ctx) 57 } 58 if len(node.OrderBy) > 0 { 59 ctx.WriteByte(' ') 60 node.OrderBy.Format(ctx) 61 } 62 if node.Limit != nil { 63 ctx.WriteByte(' ') 64 node.Limit.Format(ctx) 65 } 66 } 67 68 func (node *Delete) GetStatementType() string { return "Delete" } 69 func (node *Delete) GetQueryType() string { return QueryTypeDML } 70 71 func NewDelete(ts TableExprs, w *Where, o OrderBy, l *Limit) *Delete { 72 return &Delete{ 73 Tables: ts, 74 Where: w, 75 OrderBy: o, 76 Limit: l, 77 } 78 }