surql_parser/upstream/sql/statements/define/
namespace.rs1use super::DefineKind;
2use crate::upstream::fmt::CoverStmts;
3use crate::upstream::sql::{Expr, Literal};
4use surrealdb_types::{SqlFormat, ToSql, write_sql};
5#[derive(Clone, Debug, PartialEq, Eq)]
6#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
7pub struct DefineNamespaceStatement {
8 pub kind: DefineKind,
9 pub id: Option<u32>,
10 pub name: Expr,
11 pub comment: Expr,
12}
13impl Default for DefineNamespaceStatement {
14 fn default() -> Self {
15 Self {
16 kind: DefineKind::Default,
17 id: None,
18 name: Expr::Literal(Literal::None),
19 comment: Expr::Literal(Literal::None),
20 }
21 }
22}
23impl ToSql for DefineNamespaceStatement {
24 fn fmt_sql(&self, f: &mut String, sql_fmt: SqlFormat) {
25 write_sql!(f, sql_fmt, "DEFINE NAMESPACE");
26 match self.kind {
27 DefineKind::Default => {}
28 DefineKind::Overwrite => write_sql!(f, sql_fmt, " OVERWRITE"),
29 DefineKind::IfNotExists => write_sql!(f, sql_fmt, " IF NOT EXISTS"),
30 }
31 write_sql!(f, sql_fmt, " {}", CoverStmts(&self.name));
32 if !matches!(self.comment, Expr::Literal(Literal::None)) {
33 write_sql!(f, sql_fmt, " COMMENT {}", CoverStmts(&self.comment));
34 }
35 }
36}