Skip to main content

surrealdb_expr/expr/statements/alter/
api.rs

1use surrealdb_types::{SqlFormat, ToSql};
2
3use super::AlterKind;
4use crate::expr::statements::define::ApiAction;
5use crate::expr::statements::define::config::api::ApiConfig;
6use crate::expr::{Expr, Literal};
7use crate::sql::ApiMethod;
8
9/// A single `FOR` clause within an `ALTER API` statement.
10#[derive(Clone, Debug, Eq, PartialEq, Hash)]
11pub enum AlterApiClause {
12	/// `FOR any [config] [THEN expr | DROP THEN]`
13	ForAny {
14		config: Option<ApiConfig>,
15		fallback: AlterKind<Expr>,
16	},
17	/// `FOR method1, method2 [config] THEN expr`
18	SetAction(ApiAction),
19	/// `FOR method1, method2 DROP THEN`
20	DropAction {
21		methods: Vec<ApiMethod>,
22	},
23}
24
25#[derive(Clone, Debug, Eq, PartialEq, Hash)]
26pub struct AlterApiStatement {
27	pub path: Expr,
28	pub if_exists: bool,
29	pub clauses: Vec<AlterApiClause>,
30	pub comment: AlterKind<String>,
31}
32
33impl Default for AlterApiStatement {
34	fn default() -> Self {
35		Self {
36			path: Expr::Literal(Literal::None),
37			if_exists: false,
38			clauses: Vec::new(),
39			comment: AlterKind::None,
40		}
41	}
42}
43
44impl ToSql for AlterApiStatement {
45	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
46		let stmt: crate::sql::statements::alter::AlterApiStatement = self.clone().into();
47		stmt.fmt_sql(f, fmt);
48	}
49}