sql_fun_sqlast/sem/
create_seq.rs1use crate::{
2 sem::{AlterSequence, AstAndContextPair},
3 syn::Opt,
4};
5
6use super::{AnalysisError, FullName, ParseContext, SemAst, alter_table::AlterObjSubCommand};
7
8#[derive(Debug, Clone)]
10pub struct CreateSequence {
11 name: FullName,
12 alter_statements: Vec<AlterSequence>,
13 owner: Option<String>,
14}
15
16impl CreateSequence {
17 #[must_use]
19 pub fn new(name: &FullName) -> Self {
20 Self {
21 name: name.clone(),
22 alter_statements: Default::default(),
23 owner: Default::default(),
24 }
25 }
26
27 #[must_use]
29 pub fn name(&self) -> &FullName {
30 &self.name
31 }
32
33 pub fn apply_alter(&mut self, alter_seq: &AlterSequence) -> Result<(), AnalysisError> {
35 self.alter_statements.push(alter_seq.clone());
36
37 for cmd in alter_seq.commands() {
38 match cmd {
39 AlterObjSubCommand::ChangeOwner(s) => self.owner = Some(s.clone()),
40 AlterObjSubCommand::SetColumnDefault(_column_name, _sem_scalar_expr) => todo!(),
41 AlterObjSubCommand::AddConstraint(_constraint) => todo!(),
42 AlterObjSubCommand::ClusterOn(_) => todo!(),
43 }
44 }
45 Ok(())
46 }
47}
48
49pub fn analyze_create_seq<TParseContext>(
51 context: TParseContext,
52 _parent_schema: &Option<String>,
53 syn: crate::syn::CreateSeqStmt,
54) -> Result<AstAndContextPair<TParseContext>, AnalysisError>
55where
56 TParseContext: ParseContext,
57{
58 let Some(name) = syn.get_sequence().as_inner() else {
59 AnalysisError::raise_unexpected_none("create_seq.sequence")?
60 };
61
62 let create_sequence = CreateSequence::new(&FullName::try_from(name)?);
63 let context = context.apply_create_sequence(&create_sequence)?;
64 Ok(AstAndContextPair::new(
65 SemAst::CreateSequence(create_sequence),
66 context,
67 ))
68}