Skip to main content

surql_parser/upstream/sql/
module.rs

1// Override for sql/module.rs — too many expr/catalog From impls to auto-strip.
2// This file is copied verbatim by sync-upstream.sh after transformation.
3// Type definitions + ToSql only. No From impls (not needed for parser).
4
5use crate::compat::val::File;
6use crate::upstream::fmt::EscapeKwFreeIdent;
7use surrealdb_types::{SqlFormat, ToSql, write_sql};
8
9#[derive(Clone, Debug, Eq, PartialEq)]
10pub enum ModuleName {
11	Module(String),
12	Silo(String, String, u32, u32, u32),
13}
14
15impl ToSql for ModuleName {
16	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
17		match self {
18			ModuleName::Module(name) => {
19				write_sql!(f, fmt, "mod::{}", EscapeKwFreeIdent(name))
20			}
21			ModuleName::Silo(org, pkg, major, minor, patch) => {
22				write_sql!(
23					f,
24					fmt,
25					"silo::{}::{}<{major}.{minor}.{patch}>",
26					EscapeKwFreeIdent(org),
27					EscapeKwFreeIdent(pkg)
28				);
29			}
30		}
31	}
32}
33
34#[derive(Clone, Debug, Eq, PartialEq)]
35pub enum ModuleExecutable {
36	Surrealism(SurrealismExecutable),
37	Silo(SiloExecutable),
38}
39
40impl ToSql for ModuleExecutable {
41	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
42		match self {
43			ModuleExecutable::Surrealism(surrealism) => surrealism.fmt_sql(f, fmt),
44			ModuleExecutable::Silo(silo) => silo.fmt_sql(f, fmt),
45		}
46	}
47}
48
49#[derive(Clone, Debug, Eq, PartialEq)]
50pub struct SurrealismExecutable(pub File);
51
52impl ToSql for SurrealismExecutable {
53	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
54		self.0.fmt_sql(f, fmt);
55	}
56}
57
58#[derive(Clone, Debug, Eq, PartialEq)]
59pub struct SiloExecutable {
60	pub organisation: String,
61	pub package: String,
62	pub major: u32,
63	pub minor: u32,
64	pub patch: u32,
65}
66
67impl ToSql for SiloExecutable {
68	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
69		write_sql!(
70			f,
71			fmt,
72			"silo::{}::{}<{}.{}.{}>",
73			self.organisation,
74			self.package,
75			self.major,
76			self.minor,
77			self.patch
78		)
79	}
80}