Skip to main content

surrealdb_sql/statements/alter/
system.rs

1use surrealdb_types::{SqlFormat, ToSql, write_sql};
2
3use crate::Expr;
4use crate::statements::alter::AlterKind;
5
6#[derive(Clone, Debug, Default, Eq, PartialEq)]
7/// AST node for `ALTER SYSTEM`.
8///
9/// Supported operations:
10/// - `QUERY_TIMEOUT <duration>`: sets the global query timeout
11/// - `DROP QUERY_TIMEOUT`: clears the global query timeout
12/// - `COMPACT`: requests datastore‑wide compaction
13pub struct AlterSystemStatement {
14	/// Tri‑state alteration for the `QUERY_TIMEOUT` parameter.
15	pub query_timeout: AlterKind<Expr>,
16	/// When true, emits `COMPACT`.
17	pub compact: bool,
18}
19
20impl ToSql for AlterSystemStatement {
21	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
22		write_sql!(f, fmt, "ALTER SYSTEM");
23		match &self.query_timeout {
24			AlterKind::None => {}
25			AlterKind::Set(duration) => {
26				write_sql!(f, fmt, " QUERY_TIMEOUT {}", duration);
27			}
28			AlterKind::Drop => {
29				write_sql!(f, fmt, " DROP QUERY_TIMEOUT");
30			}
31		}
32		if self.compact {
33			write_sql!(f, fmt, " COMPACT");
34		}
35	}
36}