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

Method doc_query

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

Source from the content-addressed store, hash-verified

947 }
948
949 fn doc_query<'a, T: AstInfo>(&'a self, v: &'a Query<T>) -> RcDoc<'a> {
950 let mut docs = vec![];
951 if !v.ctes.is_empty() {
952 match &v.ctes {
953 CteBlock::Simple(ctes) => {
954 docs.push(title_comma_separate("WITH", |cte| self.doc_cte(cte), ctes))
955 }
956 CteBlock::MutuallyRecursive(mutrec) => {
957 let mut doc = RcDoc::text("WITH MUTUALLY RECURSIVE");
958 if !mutrec.options.is_empty() {
959 doc = nest(
960 doc,
961 bracket(
962 "(",
963 comma_separate(|o| self.doc_display_pass(o), &mutrec.options),
964 ")",
965 ),
966 );
967 }
968 docs.push(nest(
969 doc,
970 comma_separate(|c| self.doc_mutually_recursive(c), &mutrec.ctes),
971 ));
972 }
973 }
974 }
975 docs.push(self.doc_set_expr(&v.body));
976 if !v.order_by.is_empty() {
977 docs.push(self.doc_order_by(&v.order_by));
978 }
979
980 let offset = if let Some(offset) = &v.offset {
981 vec![RcDoc::concat([nest_title("OFFSET", self.doc_expr(offset))])]
982 } else {
983 vec![]
984 };
985
986 if let Some(limit) = &v.limit {
987 if limit.with_ties {
988 docs.extend(offset);
989 docs.push(RcDoc::concat([
990 RcDoc::text("FETCH FIRST "),
991 self.doc_expr(&limit.quantity),
992 RcDoc::text(" ROWS WITH TIES"),
993 ]));
994 } else {
995 docs.push(nest_title("LIMIT", self.doc_expr(&limit.quantity)));
996 docs.extend(offset);
997 }
998 } else {
999 docs.extend(offset);
1000 }
1001
1002 RcDoc::intersperse(docs, Doc::line()).group()
1003 }
1004
1005 fn doc_cte<'a, T: AstInfo>(&'a self, v: &'a Cte<T>) -> RcDoc<'a> {
1006 RcDoc::concat([

Callers 9

doc_subscribeMethod · 0.80
doc_view_definitionMethod · 0.80
doc_insertMethod · 0.80
doc_select_statementMethod · 0.80
doc_cteMethod · 0.80
doc_set_exprMethod · 0.80
doc_exprMethod · 0.80

Calls 15

title_comma_separateFunction · 0.85
nestFunction · 0.85
bracketFunction · 0.85
comma_separateFunction · 0.85
concatFunction · 0.85
nest_titleFunction · 0.85
doc_cteMethod · 0.80
doc_display_passMethod · 0.80
doc_set_exprMethod · 0.80
doc_order_byMethod · 0.80
doc_exprMethod · 0.80

Tested by

no test coverage detected