Skip to main content

qusql_parse/
create_option.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5// http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12
13use crate::{Identifier, Span, Spanned};
14
15/// Special algorithm used for table creation
16#[derive(Clone, Debug)]
17pub enum CreateAlgorithm {
18    Undefined(Span),
19    Merge(Span),
20    TempTable(Span),
21}
22impl Spanned for CreateAlgorithm {
23    fn span(&self) -> Span {
24        match &self {
25            CreateAlgorithm::Undefined(s) => s.span(),
26            CreateAlgorithm::Merge(s) => s.span(),
27            CreateAlgorithm::TempTable(s) => s.span(),
28        }
29    }
30}
31
32/// Options for create statement
33#[derive(Clone, Debug)]
34pub enum CreateOption<'a> {
35    OrReplace(Span),
36    /// TEMPORARY or LOCAL TEMPORARY (PostgreSQL)
37    Temporary {
38        local_span: Option<Span>,
39        temporary_span: Span,
40    },
41    /// MATERIALIZED (for VIEWs, PostgreSQL)
42    Materialized(Span),
43    /// CONCURRENTLY (for INDEX, PostgreSQL)
44    Concurrently(Span),
45    Unique(Span),
46    Algorithm(Span, CreateAlgorithm),
47    Definer {
48        definer_span: Span,
49        user: Identifier<'a>,
50        host: Identifier<'a>,
51    },
52    SqlSecurityDefiner(Span, Span),
53    SqlSecurityInvoker(Span, Span),
54    SqlSecurityUser(Span, Span),
55}
56impl<'a> Spanned for CreateOption<'a> {
57    fn span(&self) -> Span {
58        match &self {
59            CreateOption::OrReplace(v) => v.span(),
60            CreateOption::Temporary {
61                local_span,
62                temporary_span,
63            } => temporary_span.join_span(local_span),
64            CreateOption::Materialized(v) => v.span(),
65            CreateOption::Concurrently(v) => v.span(),
66            CreateOption::Algorithm(s, a) => s.join_span(a),
67            CreateOption::Definer {
68                definer_span,
69                user,
70                host,
71            } => definer_span.join_span(user).join_span(host),
72            CreateOption::SqlSecurityDefiner(a, b) => a.join_span(b),
73            CreateOption::SqlSecurityInvoker(a, b) => a.join_span(b),
74            CreateOption::SqlSecurityUser(a, b) => a.join_span(b),
75            CreateOption::Unique(v) => v.span(),
76        }
77    }
78}