surrealdb_core/sql/statements/
delete.rs

1use std::fmt;
2
3use crate::sql::fmt::Fmt;
4use crate::sql::{Cond, Explain, Expr, Output, Timeout, With};
5
6#[derive(Clone, Debug, Default, Eq, PartialEq)]
7#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
8pub struct DeleteStatement {
9	pub only: bool,
10	pub what: Vec<Expr>,
11	pub with: Option<With>,
12	pub cond: Option<Cond>,
13	pub output: Option<Output>,
14	pub timeout: Option<Timeout>,
15	pub parallel: bool,
16	pub explain: Option<Explain>,
17}
18
19impl fmt::Display for DeleteStatement {
20	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21		write!(f, "DELETE")?;
22		if self.only {
23			f.write_str(" ONLY")?
24		}
25		write!(f, " {}", Fmt::comma_separated(self.what.iter()))?;
26		if let Some(ref v) = self.with {
27			write!(f, " {v}")?
28		}
29		if let Some(ref v) = self.cond {
30			write!(f, " {v}")?
31		}
32		if let Some(ref v) = self.output {
33			write!(f, " {v}")?
34		}
35		if let Some(ref v) = self.timeout {
36			write!(f, " {v}")?
37		}
38		if self.parallel {
39			f.write_str(" PARALLEL")?
40		}
41		if let Some(ref v) = self.explain {
42			write!(f, " {v}")?
43		}
44		Ok(())
45	}
46}
47
48impl From<DeleteStatement> for crate::expr::statements::DeleteStatement {
49	fn from(v: DeleteStatement) -> Self {
50		crate::expr::statements::DeleteStatement {
51			only: v.only,
52			what: v.what.into_iter().map(From::from).collect(),
53			with: v.with.map(Into::into),
54			cond: v.cond.map(Into::into),
55			output: v.output.map(Into::into),
56			timeout: v.timeout.map(Into::into),
57			parallel: v.parallel,
58			explain: v.explain.map(Into::into),
59		}
60	}
61}
62
63impl From<crate::expr::statements::DeleteStatement> for DeleteStatement {
64	fn from(v: crate::expr::statements::DeleteStatement) -> Self {
65		DeleteStatement {
66			only: v.only,
67			what: v.what.into_iter().map(From::from).collect(),
68			with: v.with.map(Into::into),
69			cond: v.cond.map(Into::into),
70			output: v.output.map(Into::into),
71			timeout: v.timeout.map(Into::into),
72			parallel: v.parallel,
73			explain: v.explain.map(Into::into),
74		}
75	}
76}