|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +//! Implementations of the `From` trait to convert from various |
| 19 | +//! AST nodes to `Statement` nodes. |
| 20 | +
|
| 21 | +use crate::ast::{ |
| 22 | + AlterSchema, AlterType, CaseStatement, CreateConnector, CreateDomain, CreateFunction, |
| 23 | + CreateIndex, CreateServerStatement, CreateTable, CreateTrigger, CreateUser, Delete, |
| 24 | + DenyStatement, DropDomain, DropTrigger, ExportData, Function, IfStatement, Insert, |
| 25 | + OpenStatement, PrintStatement, Query, RaiseStatement, RenameTable, ReturnStatement, Set, |
| 26 | + ShowCharset, ShowObjects, Statement, Use, VacuumStatement, WhileStatement, |
| 27 | +}; |
| 28 | + |
| 29 | +impl From<Set> for Statement { |
| 30 | + fn from(s: Set) -> Self { |
| 31 | + Self::Set(s) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +impl From<Query> for Statement { |
| 36 | + fn from(q: Query) -> Self { |
| 37 | + Box::new(q).into() |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +impl From<Box<Query>> for Statement { |
| 42 | + fn from(q: Box<Query>) -> Self { |
| 43 | + Self::Query(q) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +impl From<Insert> for Statement { |
| 48 | + fn from(i: Insert) -> Self { |
| 49 | + Self::Insert(i) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +impl From<CaseStatement> for Statement { |
| 54 | + fn from(c: CaseStatement) -> Self { |
| 55 | + Self::Case(c) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +impl From<IfStatement> for Statement { |
| 60 | + fn from(i: IfStatement) -> Self { |
| 61 | + Self::If(i) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +impl From<WhileStatement> for Statement { |
| 66 | + fn from(w: WhileStatement) -> Self { |
| 67 | + Self::While(w) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +impl From<RaiseStatement> for Statement { |
| 72 | + fn from(r: RaiseStatement) -> Self { |
| 73 | + Self::Raise(r) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +impl From<Function> for Statement { |
| 78 | + fn from(f: Function) -> Self { |
| 79 | + Self::Call(f) |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +impl From<OpenStatement> for Statement { |
| 84 | + fn from(o: OpenStatement) -> Self { |
| 85 | + Self::Open(o) |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +impl From<Delete> for Statement { |
| 90 | + fn from(d: Delete) -> Self { |
| 91 | + Self::Delete(d) |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +impl From<CreateTable> for Statement { |
| 96 | + fn from(c: CreateTable) -> Self { |
| 97 | + Self::CreateTable(c) |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +impl From<CreateIndex> for Statement { |
| 102 | + fn from(c: CreateIndex) -> Self { |
| 103 | + Self::CreateIndex(c) |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +impl From<CreateServerStatement> for Statement { |
| 108 | + fn from(c: CreateServerStatement) -> Self { |
| 109 | + Self::CreateServer(c) |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +impl From<CreateConnector> for Statement { |
| 114 | + fn from(c: CreateConnector) -> Self { |
| 115 | + Self::CreateConnector(c) |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +impl From<AlterSchema> for Statement { |
| 120 | + fn from(a: AlterSchema) -> Self { |
| 121 | + Self::AlterSchema(a) |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +impl From<AlterType> for Statement { |
| 126 | + fn from(a: AlterType) -> Self { |
| 127 | + Self::AlterType(a) |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +impl From<DropDomain> for Statement { |
| 132 | + fn from(d: DropDomain) -> Self { |
| 133 | + Self::DropDomain(d) |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +impl From<ShowCharset> for Statement { |
| 138 | + fn from(s: ShowCharset) -> Self { |
| 139 | + Self::ShowCharset(s) |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +impl From<ShowObjects> for Statement { |
| 144 | + fn from(s: ShowObjects) -> Self { |
| 145 | + Self::ShowObjects(s) |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | +impl From<Use> for Statement { |
| 150 | + fn from(u: Use) -> Self { |
| 151 | + Self::Use(u) |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | +impl From<CreateFunction> for Statement { |
| 156 | + fn from(c: CreateFunction) -> Self { |
| 157 | + Self::CreateFunction(c) |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +impl From<CreateTrigger> for Statement { |
| 162 | + fn from(c: CreateTrigger) -> Self { |
| 163 | + Self::CreateTrigger(c) |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +impl From<DropTrigger> for Statement { |
| 168 | + fn from(d: DropTrigger) -> Self { |
| 169 | + Self::DropTrigger(d) |
| 170 | + } |
| 171 | +} |
| 172 | + |
| 173 | +impl From<DenyStatement> for Statement { |
| 174 | + fn from(d: DenyStatement) -> Self { |
| 175 | + Self::Deny(d) |
| 176 | + } |
| 177 | +} |
| 178 | + |
| 179 | +impl From<CreateDomain> for Statement { |
| 180 | + fn from(c: CreateDomain) -> Self { |
| 181 | + Self::CreateDomain(c) |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +impl From<RenameTable> for Statement { |
| 186 | + fn from(r: RenameTable) -> Self { |
| 187 | + vec![r].into() |
| 188 | + } |
| 189 | +} |
| 190 | + |
| 191 | +impl From<Vec<RenameTable>> for Statement { |
| 192 | + fn from(r: Vec<RenameTable>) -> Self { |
| 193 | + Self::RenameTable(r) |
| 194 | + } |
| 195 | +} |
| 196 | + |
| 197 | +impl From<PrintStatement> for Statement { |
| 198 | + fn from(p: PrintStatement) -> Self { |
| 199 | + Self::Print(p) |
| 200 | + } |
| 201 | +} |
| 202 | + |
| 203 | +impl From<ReturnStatement> for Statement { |
| 204 | + fn from(r: ReturnStatement) -> Self { |
| 205 | + Self::Return(r) |
| 206 | + } |
| 207 | +} |
| 208 | + |
| 209 | +impl From<ExportData> for Statement { |
| 210 | + fn from(e: ExportData) -> Self { |
| 211 | + Self::ExportData(e) |
| 212 | + } |
| 213 | +} |
| 214 | + |
| 215 | +impl From<CreateUser> for Statement { |
| 216 | + fn from(c: CreateUser) -> Self { |
| 217 | + Self::CreateUser(c) |
| 218 | + } |
| 219 | +} |
| 220 | + |
| 221 | +impl From<VacuumStatement> for Statement { |
| 222 | + fn from(v: VacuumStatement) -> Self { |
| 223 | + Self::Vacuum(v) |
| 224 | + } |
| 225 | +} |
0 commit comments