surrealdb_core/sql/statements/alter/
mod.rs

1mod table;
2
3pub use table::AlterTableStatement;
4
5use crate::ctx::Context;
6use crate::dbs::Options;
7use crate::doc::CursorDoc;
8use crate::err::Error;
9use crate::sql::value::Value;
10
11use reblessive::tree::Stk;
12use revision::revisioned;
13use serde::{Deserialize, Serialize};
14use std::fmt::{self, Display};
15
16#[revisioned(revision = 1)]
17#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
18#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
19#[non_exhaustive]
20pub enum AlterStatement {
21	Table(AlterTableStatement),
22}
23
24impl AlterStatement {
25	/// Check if we require a writeable transaction
26	pub(crate) fn writeable(&self) -> bool {
27		true
28	}
29	/// Process this type returning a computed simple Value
30	pub(crate) async fn compute(
31		&self,
32		stk: &mut Stk,
33		ctx: &Context,
34		opt: &Options,
35		doc: Option<&CursorDoc>,
36	) -> Result<Value, Error> {
37		match self {
38			Self::Table(ref v) => v.compute(stk, ctx, opt, doc).await,
39		}
40	}
41}
42
43impl Display for AlterStatement {
44	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45		match self {
46			Self::Table(v) => Display::fmt(v, f),
47		}
48	}
49}
50
51#[cfg(test)]
52mod tests {
53
54	use super::*;
55	use crate::sql::Ident;
56
57	#[test]
58	fn check_alter_serialize() {
59		let stm = AlterStatement::Table(AlterTableStatement {
60			name: Ident::from("test"),
61			..Default::default()
62		});
63		let enc: Vec<u8> = revision::to_vec(&stm).unwrap();
64		assert_eq!(16, enc.len());
65	}
66}