LCOV - code coverage report
Current view: top level - dashql-core/src/formatter - delete.rs Coverage Total Hit
Test: DashQL 915828b Lines: 90.9 % 22 20
Test Date: 2026-11-06 19:30:32

            Line data    Source code
       1              : //! DELETE statements.
       2              : 
       3              : use dashql_parser::attrs;
       4              : use super::{FmtReg, Formatter, FormattingJoinPolicy, K};
       5              : use dashql_buffers::parser::Node;
       6              : 
       7              : impl<'a> Formatter<'a> {
       8           84 :     pub(super) fn format_delete(&self, node: &'a Node) -> FmtReg {
       9           84 :         let f = &self.fmt;
      10           84 :         let [target, using_clause, where_clause, returning, with_ctes, with_recursive] = attrs!(self.children(node), [
      11              :                 K::SQL_DELETE_TARGET,
      12              :                 K::SQL_DELETE_USING,
      13              :                 K::SQL_DELETE_WHERE,
      14              :                 K::SQL_DELETE_RETURNING,
      15              :                 K::SQL_SELECT_WITH_CTES,
      16              :                 K::SQL_SELECT_WITH_RECURSIVE,
      17              :             ],
      18              :         );
      19           84 :         let Some(target) = target.filter(|t| self.reg(t) != 0) else { return self.format_unimplemented(node) };
      20              : 
      21           84 :         let mut clauses = Vec::new();
      22           84 :         if let Some(with_ctes) = with_ctes {
      23           15 :             if self.reg(with_ctes) == 0 {
      24            0 :                 return self.format_unimplemented(with_ctes);
      25           15 :             }
      26           15 :             let keyword = if with_recursive.is_some() { "with recursive " } else { "with " };
      27           15 :             clauses.push(f.concat(&[f.text(keyword), self.reg(with_ctes)]));
      28           69 :         }
      29           84 :         clauses.push(f.concat(&[f.text("delete from "), self.reg(target)]));
      30          252 :         for (child, keyword) in [(using_clause, "using "), (where_clause, "where "), (returning, "returning ")] {
      31          252 :             let Some(child) = child else { continue };
      32          135 :             if self.reg(child) == 0 {
      33            0 :                 return self.format_unimplemented(child);
      34          135 :             }
      35          135 :             clauses.push(f.concat(&[f.text(keyword), self.reg(child)]));
      36              :         }
      37           84 :         let policy = self.pretty_policy(FormattingJoinPolicy::BreakAllOrNone);
      38           84 :         self.space_join(&clauses, policy, false)
      39           84 :     }
      40              : }
        

Generated by: LCOV version 2.0-1