MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / doc_subscribe

Method doc_subscribe

src/sql-pretty/src/doc.rs:634–690  ·  view source on GitHub ↗
(
        &'a self,
        v: &'a SubscribeStatement<T>,
    )

Source from the content-addressed store, hash-verified

632 }
633
634 pub(crate) fn doc_subscribe<'a, T: AstInfo>(
635 &'a self,
636 v: &'a SubscribeStatement<T>,
637 ) -> RcDoc<'a> {
638 let doc = match &v.relation {
639 SubscribeRelation::Name(name) => {
640 let title = if v.relation.needs_explicit_to(matches!(
641 self.config.format_mode,
642 FormatMode::Simple | FormatMode::SimpleRedacted
643 )) {
644 "SUBSCRIBE TO"
645 } else {
646 "SUBSCRIBE"
647 };
648 nest_title(title, self.doc_display_pass(name))
649 }
650 SubscribeRelation::Query(query) => bracket("SUBSCRIBE (", self.doc_query(query), ")"),
651 };
652 let mut docs = vec![doc];
653 if !v.options.is_empty() {
654 docs.push(bracket(
655 "WITH (",
656 comma_separate(|o| self.doc_display_pass(o), &v.options),
657 ")",
658 ));
659 }
660 if let Some(as_of) = &v.as_of {
661 docs.push(self.doc_as_of(as_of));
662 }
663 if let Some(up_to) = &v.up_to {
664 docs.push(nest_title("UP TO", self.doc_expr(up_to)));
665 }
666 match &v.output {
667 SubscribeOutput::Diffs => {}
668 SubscribeOutput::WithinTimestampOrderBy { order_by } => {
669 docs.push(nest_title(
670 "WITHIN TIMESTAMP ORDER BY ",
671 comma_separate(|o| self.doc_order_by_expr(o), order_by),
672 ));
673 }
674 SubscribeOutput::EnvelopeUpsert { key_columns } => {
675 docs.push(bracket(
676 "ENVELOPE UPSERT (KEY (",
677 comma_separate(|kc| self.doc_display_pass(kc), key_columns),
678 "))",
679 ));
680 }
681 SubscribeOutput::EnvelopeDebezium { key_columns } => {
682 docs.push(bracket(
683 "ENVELOPE DEBEZIUM (KEY (",
684 comma_separate(|kc| self.doc_display_pass(kc), key_columns),
685 "))",
686 ));
687 }
688 }
689 RcDoc::intersperse(docs, Doc::line()).group()
690 }
691

Callers 2

to_docMethod · 0.80
doc_copyMethod · 0.80

Calls 12

nest_titleFunction · 0.85
bracketFunction · 0.85
comma_separateFunction · 0.85
needs_explicit_toMethod · 0.80
doc_display_passMethod · 0.80
doc_queryMethod · 0.80
doc_as_ofMethod · 0.80
doc_exprMethod · 0.80
doc_order_by_exprMethod · 0.80
groupMethod · 0.80
is_emptyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected