mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-26 23:49:10 +00:00
Implemented the From
method for all clear variants in Statement (#2028)
This commit is contained in:
parent
e3fbfd91b2
commit
7021561474
3 changed files with 208 additions and 14 deletions
|
@ -432,7 +432,7 @@ impl CreateTableBuilder {
|
|||
}
|
||||
|
||||
pub fn build(self) -> Statement {
|
||||
Statement::CreateTable(CreateTable {
|
||||
CreateTable {
|
||||
or_replace: self.or_replace,
|
||||
temporary: self.temporary,
|
||||
external: self.external,
|
||||
|
@ -484,7 +484,8 @@ impl CreateTableBuilder {
|
|||
refresh_mode: self.refresh_mode,
|
||||
initialize: self.initialize,
|
||||
require_user: self.require_user,
|
||||
})
|
||||
}
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
207
src/ast/mod.rs
207
src/ast/mod.rs
|
@ -21,6 +21,7 @@ use alloc::{
|
|||
boxed::Box,
|
||||
format,
|
||||
string::{String, ToString},
|
||||
vec,
|
||||
vec::Vec,
|
||||
};
|
||||
use helpers::{
|
||||
|
@ -3029,14 +3030,6 @@ impl Display for Set {
|
|||
}
|
||||
}
|
||||
|
||||
/// Convert a `Set` into a `Statement`.
|
||||
/// Convenience function, instead of writing `Statement::Set(Set::Set...{...})`
|
||||
impl From<Set> for Statement {
|
||||
fn from(set: Set) -> Self {
|
||||
Statement::Set(set)
|
||||
}
|
||||
}
|
||||
|
||||
/// A representation of a `WHEN` arm with all the identifiers catched and the statements to execute
|
||||
/// for the arm.
|
||||
///
|
||||
|
@ -10707,6 +10700,204 @@ impl fmt::Display for VacuumStatement {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Set> for Statement {
|
||||
fn from(s: Set) -> Self {
|
||||
Self::Set(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Query> for Statement {
|
||||
fn from(q: Query) -> Self {
|
||||
Box::new(q).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<Query>> for Statement {
|
||||
fn from(q: Box<Query>) -> Self {
|
||||
Self::Query(q)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Insert> for Statement {
|
||||
fn from(i: Insert) -> Self {
|
||||
Self::Insert(i)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CaseStatement> for Statement {
|
||||
fn from(c: CaseStatement) -> Self {
|
||||
Self::Case(c)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IfStatement> for Statement {
|
||||
fn from(i: IfStatement) -> Self {
|
||||
Self::If(i)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WhileStatement> for Statement {
|
||||
fn from(w: WhileStatement) -> Self {
|
||||
Self::While(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RaiseStatement> for Statement {
|
||||
fn from(r: RaiseStatement) -> Self {
|
||||
Self::Raise(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Function> for Statement {
|
||||
fn from(f: Function) -> Self {
|
||||
Self::Call(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OpenStatement> for Statement {
|
||||
fn from(o: OpenStatement) -> Self {
|
||||
Self::Open(o)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Delete> for Statement {
|
||||
fn from(d: Delete) -> Self {
|
||||
Self::Delete(d)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateTable> for Statement {
|
||||
fn from(c: CreateTable) -> Self {
|
||||
Self::CreateTable(c)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateIndex> for Statement {
|
||||
fn from(c: CreateIndex) -> Self {
|
||||
Self::CreateIndex(c)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateServerStatement> for Statement {
|
||||
fn from(c: CreateServerStatement) -> Self {
|
||||
Self::CreateServer(c)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateConnector> for Statement {
|
||||
fn from(c: CreateConnector) -> Self {
|
||||
Self::CreateConnector(c)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AlterSchema> for Statement {
|
||||
fn from(a: AlterSchema) -> Self {
|
||||
Self::AlterSchema(a)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AlterType> for Statement {
|
||||
fn from(a: AlterType) -> Self {
|
||||
Self::AlterType(a)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DropDomain> for Statement {
|
||||
fn from(d: DropDomain) -> Self {
|
||||
Self::DropDomain(d)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ShowCharset> for Statement {
|
||||
fn from(s: ShowCharset) -> Self {
|
||||
Self::ShowCharset(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ShowObjects> for Statement {
|
||||
fn from(s: ShowObjects) -> Self {
|
||||
Self::ShowObjects(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Use> for Statement {
|
||||
fn from(u: Use) -> Self {
|
||||
Self::Use(u)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateFunction> for Statement {
|
||||
fn from(c: CreateFunction) -> Self {
|
||||
Self::CreateFunction(c)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateTrigger> for Statement {
|
||||
fn from(c: CreateTrigger) -> Self {
|
||||
Self::CreateTrigger(c)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DropTrigger> for Statement {
|
||||
fn from(d: DropTrigger) -> Self {
|
||||
Self::DropTrigger(d)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DenyStatement> for Statement {
|
||||
fn from(d: DenyStatement) -> Self {
|
||||
Self::Deny(d)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateDomain> for Statement {
|
||||
fn from(c: CreateDomain) -> Self {
|
||||
Self::CreateDomain(c)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RenameTable> for Statement {
|
||||
fn from(r: RenameTable) -> Self {
|
||||
vec![r].into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<RenameTable>> for Statement {
|
||||
fn from(r: Vec<RenameTable>) -> Self {
|
||||
Self::RenameTable(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PrintStatement> for Statement {
|
||||
fn from(p: PrintStatement) -> Self {
|
||||
Self::Print(p)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ReturnStatement> for Statement {
|
||||
fn from(r: ReturnStatement) -> Self {
|
||||
Self::Return(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ExportData> for Statement {
|
||||
fn from(e: ExportData) -> Self {
|
||||
Self::ExportData(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CreateUser> for Statement {
|
||||
fn from(c: CreateUser) -> Self {
|
||||
Self::CreateUser(c)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VacuumStatement> for Statement {
|
||||
fn from(v: VacuumStatement) -> Self {
|
||||
Self::Vacuum(v)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tokenizer::Location;
|
||||
|
|
|
@ -226,12 +226,13 @@ impl MsSqlDialect {
|
|||
parser.prev_token();
|
||||
}
|
||||
|
||||
Ok(Statement::If(IfStatement {
|
||||
Ok(IfStatement {
|
||||
if_block,
|
||||
else_block,
|
||||
elseif_blocks: Vec::new(),
|
||||
end_token: None,
|
||||
}))
|
||||
}
|
||||
.into())
|
||||
}
|
||||
|
||||
/// Parse `CREATE TRIGGER` for [MsSql]
|
||||
|
@ -251,7 +252,7 @@ impl MsSqlDialect {
|
|||
parser.expect_keyword_is(Keyword::AS)?;
|
||||
let statements = Some(parser.parse_conditional_statements(&[Keyword::END])?);
|
||||
|
||||
Ok(Statement::CreateTrigger(CreateTrigger {
|
||||
Ok(CreateTrigger {
|
||||
or_alter,
|
||||
or_replace: false,
|
||||
is_constraint: false,
|
||||
|
@ -269,7 +270,8 @@ impl MsSqlDialect {
|
|||
statements_as: true,
|
||||
statements,
|
||||
characteristics: None,
|
||||
}))
|
||||
}
|
||||
.into())
|
||||
}
|
||||
|
||||
/// Parse a sequence of statements, optionally separated by semicolon.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue