github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/parsers/tree/drop.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 // DROP Database statement 18 type DropDatabase struct { 19 statementImpl 20 Name Identifier 21 IfExists bool 22 } 23 24 func (node *DropDatabase) Format(ctx *FmtCtx) { 25 ctx.WriteString("drop database") 26 if node.IfExists { 27 ctx.WriteByte(' ') 28 ctx.WriteString("if exists") 29 } 30 if node.Name != "" { 31 ctx.WriteByte(' ') 32 ctx.WriteString(string(node.Name)) 33 } 34 } 35 36 func (node *DropDatabase) GetStatementType() string { return "Drop Database" } 37 func (node *DropDatabase) GetQueryType() string { return QueryTypeDDL } 38 39 func NewDropDatabase(n Identifier, i bool) *DropDatabase { 40 return &DropDatabase{ 41 Name: n, 42 IfExists: i, 43 } 44 } 45 46 // DROP Table statement 47 type DropTable struct { 48 statementImpl 49 IfExists bool 50 Names TableNames 51 } 52 53 func (node *DropTable) Format(ctx *FmtCtx) { 54 ctx.WriteString("drop table") 55 if node.IfExists { 56 ctx.WriteString(" if exists") 57 } 58 ctx.WriteByte(' ') 59 node.Names.Format(ctx) 60 } 61 62 func (node *DropTable) GetStatementType() string { return "Drop Table" } 63 func (node *DropTable) GetQueryType() string { return QueryTypeDDL } 64 65 func NewDropTable(i bool, n TableNames) *DropTable { 66 return &DropTable{ 67 IfExists: i, 68 Names: n, 69 } 70 } 71 72 // DropView DROP View statement 73 type DropView struct { 74 statementImpl 75 IfExists bool 76 Names TableNames 77 } 78 79 func (node *DropView) Format(ctx *FmtCtx) { 80 ctx.WriteString("drop view") 81 if node.IfExists { 82 ctx.WriteString(" if exists") 83 } 84 ctx.WriteByte(' ') 85 node.Names.Format(ctx) 86 } 87 88 func (node *DropView) GetStatementType() string { return "Drop View" } 89 func (node *DropView) GetQueryType() string { return QueryTypeDDL } 90 91 func NewDropView(i bool, n TableNames) *DropView { 92 return &DropView{ 93 IfExists: i, 94 Names: n, 95 } 96 } 97 98 type DropIndex struct { 99 statementImpl 100 Name Identifier 101 TableName TableName 102 IfExists bool 103 MiscOption []MiscOption 104 } 105 106 func (node *DropIndex) Format(ctx *FmtCtx) { 107 ctx.WriteString("drop index") 108 if node.IfExists { 109 ctx.WriteString(" if exists") 110 } 111 ctx.WriteByte(' ') 112 ctx.WriteString(string(node.Name)) 113 114 ctx.WriteString(" on ") 115 node.TableName.Format(ctx) 116 } 117 118 func (node *DropIndex) GetStatementType() string { return "Drop Index" } 119 func (node *DropIndex) GetQueryType() string { return QueryTypeDDL } 120 121 func NewDropIndex(i Identifier, t TableName, ife bool, m []MiscOption) *DropIndex { 122 return &DropIndex{ 123 Name: i, 124 TableName: t, 125 IfExists: ife, 126 MiscOption: m, 127 } 128 } 129 130 type DropRole struct { 131 statementImpl 132 IfExists bool 133 Roles []*Role 134 } 135 136 func (node *DropRole) Format(ctx *FmtCtx) { 137 ctx.WriteString("drop role") 138 if node.IfExists { 139 ctx.WriteString(" if exists") 140 } 141 prefix := " " 142 for _, r := range node.Roles { 143 ctx.WriteString(prefix) 144 r.Format(ctx) 145 prefix = ", " 146 } 147 } 148 149 func (node *DropRole) GetStatementType() string { return "Drop Role" } 150 func (node *DropRole) GetQueryType() string { return QueryTypeDCL } 151 152 func NewDropRole(ife bool, r []*Role) *DropRole { 153 return &DropRole{ 154 IfExists: ife, 155 Roles: r, 156 } 157 } 158 159 type DropUser struct { 160 statementImpl 161 IfExists bool 162 Users []*User 163 } 164 165 func (node *DropUser) Format(ctx *FmtCtx) { 166 ctx.WriteString("drop user") 167 if node.IfExists { 168 ctx.WriteString(" if exists") 169 } 170 prefix := " " 171 for _, u := range node.Users { 172 ctx.WriteString(prefix) 173 u.Format(ctx) 174 prefix = ", " 175 } 176 } 177 178 func (node *DropUser) GetStatementType() string { return "Drop User" } 179 func (node *DropUser) GetQueryType() string { return QueryTypeDCL } 180 181 func NewDropUser(ife bool, u []*User) *DropUser { 182 return &DropUser{ 183 IfExists: ife, 184 Users: u, 185 } 186 } 187 188 type DropAccount struct { 189 statementImpl 190 IfExists bool 191 Name string 192 } 193 194 func (node *DropAccount) Format(ctx *FmtCtx) { 195 ctx.WriteString("drop account") 196 if node.IfExists { 197 ctx.WriteString(" if exists") 198 } 199 ctx.WriteString(" ") 200 ctx.WriteString(node.Name) 201 } 202 203 func (node *DropAccount) GetStatementType() string { return "Drop Account" } 204 func (node *DropAccount) GetQueryType() string { return QueryTypeDCL }