surrealdb_sql/statements/define/
module.rs1use surrealdb_types::{SqlFormat, ToSql, write_sql};
2
3use super::DefineKind;
4use crate::{CoverStmts, Expr, Ident, Literal, ModuleExecutable, Permission};
5
6#[derive(Clone, Debug, PartialEq, Eq)]
7#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
8pub struct DefineModuleStatement {
9 pub kind: DefineKind,
10 pub name: Option<Ident>,
11 pub executable: ModuleExecutable,
12 #[cfg_attr(feature = "arbitrary", arbitrary(value = true))]
22 pub unsigned: bool,
23 pub comment: Expr,
24 pub permissions: Permission,
25}
26
27impl ToSql for DefineModuleStatement {
28 fn fmt_sql(&self, f: &mut String, sql_fmt: SqlFormat) {
29 f.push_str("DEFINE MODULE");
30 match self.kind {
31 DefineKind::Default => {}
32 DefineKind::Overwrite => f.push_str(" OVERWRITE"),
33 DefineKind::IfNotExists => f.push_str(" IF NOT EXISTS"),
34 }
35 if let Some(name) = &self.name {
36 write_sql!(f, sql_fmt, " mod::{} FROM", name);
37 }
38 write_sql!(f, sql_fmt, " {}", self.executable);
39 if self.unsigned {
40 f.push_str(" UNSIGNED");
41 }
42 if !matches!(self.comment, Expr::Literal(Literal::None)) {
43 write_sql!(f, sql_fmt, " COMMENT {}", CoverStmts(&self.comment));
44 }
45 if sql_fmt.is_pretty() {
46 f.push('\n');
47 sql_fmt.write_indent(f);
48 } else {
49 f.push(' ');
50 }
51 write_sql!(f, sql_fmt, "PERMISSIONS {}", self.permissions);
52 }
53}