surrealdb_core/sql/statements/remove/
mod.rs

1mod access;
2mod analyzer;
3mod database;
4mod event;
5mod field;
6mod function;
7mod index;
8mod model;
9mod namespace;
10mod param;
11mod table;
12mod user;
13
14pub use access::RemoveAccessStatement;
15pub use analyzer::RemoveAnalyzerStatement;
16pub use database::RemoveDatabaseStatement;
17pub use event::RemoveEventStatement;
18pub use field::RemoveFieldStatement;
19pub use function::RemoveFunctionStatement;
20pub use index::RemoveIndexStatement;
21pub use model::RemoveModelStatement;
22pub use namespace::RemoveNamespaceStatement;
23pub use param::RemoveParamStatement;
24pub use table::RemoveTableStatement;
25pub use user::RemoveUserStatement;
26
27use crate::ctx::Context;
28use crate::dbs::Options;
29use crate::doc::CursorDoc;
30use crate::err::Error;
31use crate::sql::Value;
32
33use revision::revisioned;
34use serde::{Deserialize, Serialize};
35use std::fmt::{self, Display, Formatter};
36
37#[revisioned(revision = 1)]
38#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
39#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
40#[non_exhaustive]
41pub enum RemoveStatement {
42	Namespace(RemoveNamespaceStatement),
43	Database(RemoveDatabaseStatement),
44	Function(RemoveFunctionStatement),
45	Analyzer(RemoveAnalyzerStatement),
46	Access(RemoveAccessStatement),
47	Param(RemoveParamStatement),
48	Table(RemoveTableStatement),
49	Event(RemoveEventStatement),
50	Field(RemoveFieldStatement),
51	Index(RemoveIndexStatement),
52	User(RemoveUserStatement),
53	Model(RemoveModelStatement),
54}
55
56impl RemoveStatement {
57	/// Check if we require a writeable transaction
58	pub(crate) fn writeable(&self) -> bool {
59		true
60	}
61	/// Process this type returning a computed simple Value
62	pub(crate) async fn compute(
63		&self,
64		ctx: &Context,
65		opt: &Options,
66		_doc: Option<&CursorDoc>,
67	) -> Result<Value, Error> {
68		match self {
69			Self::Namespace(ref v) => v.compute(ctx, opt).await,
70			Self::Database(ref v) => v.compute(ctx, opt).await,
71			Self::Function(ref v) => v.compute(ctx, opt).await,
72			Self::Access(ref v) => v.compute(ctx, opt).await,
73			Self::Param(ref v) => v.compute(ctx, opt).await,
74			Self::Table(ref v) => v.compute(ctx, opt).await,
75			Self::Event(ref v) => v.compute(ctx, opt).await,
76			Self::Field(ref v) => v.compute(ctx, opt).await,
77			Self::Index(ref v) => v.compute(ctx, opt).await,
78			Self::Analyzer(ref v) => v.compute(ctx, opt).await,
79			Self::User(ref v) => v.compute(ctx, opt).await,
80			Self::Model(ref v) => v.compute(ctx, opt).await,
81		}
82	}
83}
84
85impl Display for RemoveStatement {
86	fn fmt(&self, f: &mut Formatter) -> fmt::Result {
87		match self {
88			Self::Namespace(v) => Display::fmt(v, f),
89			Self::Database(v) => Display::fmt(v, f),
90			Self::Function(v) => Display::fmt(v, f),
91			Self::Access(v) => Display::fmt(v, f),
92			Self::Param(v) => Display::fmt(v, f),
93			Self::Table(v) => Display::fmt(v, f),
94			Self::Event(v) => Display::fmt(v, f),
95			Self::Field(v) => Display::fmt(v, f),
96			Self::Index(v) => Display::fmt(v, f),
97			Self::Analyzer(v) => Display::fmt(v, f),
98			Self::User(v) => Display::fmt(v, f),
99			Self::Model(v) => Display::fmt(v, f),
100		}
101	}
102}