Skip to main content

surrealdb_sql/
module.rs

1use common::fmt::EscapeKwFreeIdent;
2use surrealdb_types::{SqlFormat, ToSql, write_sql};
3
4use crate::file::File;
5
6#[derive(Clone, Debug, Eq, PartialEq)]
7#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
8pub enum ModuleName {
9	Module(String),
10	Silo(String, String, u32, u32, u32),
11}
12
13impl ToSql for ModuleName {
14	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
15		match self {
16			ModuleName::Module(name) => write_sql!(f, fmt, "mod::{}", EscapeKwFreeIdent(name)),
17			ModuleName::Silo(org, pkg, major, minor, patch) => {
18				write_sql!(
19					f,
20					fmt,
21					"silo::{}::{}::<{major}.{minor}.{patch}>",
22					EscapeKwFreeIdent(org),
23					EscapeKwFreeIdent(pkg)
24				);
25			}
26		}
27	}
28}
29
30#[derive(Clone, Debug, Eq, PartialEq)]
31#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
32pub enum ModuleExecutable {
33	Surrealism(SurrealismExecutable),
34	Silo(SiloExecutable),
35}
36
37impl ToSql for ModuleExecutable {
38	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
39		match self {
40			ModuleExecutable::Surrealism(surrealism) => surrealism.fmt_sql(f, fmt),
41			ModuleExecutable::Silo(silo) => silo.fmt_sql(f, fmt),
42		}
43	}
44}
45
46#[derive(Clone, Debug, Eq, PartialEq)]
47#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
48pub struct SurrealismExecutable(pub File);
49
50impl ToSql for SurrealismExecutable {
51	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
52		self.0.fmt_sql(f, fmt);
53	}
54}
55
56#[derive(Clone, Debug, Eq, PartialEq)]
57#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
58pub struct SiloExecutable {
59	pub organisation: String,
60	pub package: String,
61	pub major: u32,
62	pub minor: u32,
63	pub patch: u32,
64}
65
66impl ToSql for SiloExecutable {
67	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
68		write_sql!(
69			f,
70			fmt,
71			"silo::{}::{}::<{}.{}.{}>",
72			self.organisation,
73			self.package,
74			self.major,
75			self.minor,
76			self.patch
77		)
78	}
79}