MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / try_parse

Function try_parse

nodedb-sql/src/ddl_ast/parse/schedule.rs:32–86  ·  view source on GitHub ↗
(
    upper: &str,
    parts: &[&str],
    trimmed: &str,
)

Source from the content-addressed store, hash-verified

30}
31
32pub(super) fn try_parse(
33 upper: &str,
34 parts: &[&str],
35 trimmed: &str,
36) -> Option<Result<NodedbStatement, SqlError>> {
37 (|| -> Result<Option<NodedbStatement>, SqlError> {
38 if upper.starts_with("CREATE SCHEDULE ") {
39 return Ok(Some(parse_create_schedule(upper, trimmed)));
40 }
41 if upper.starts_with("DROP SCHEDULE ") {
42 let if_exists = upper.contains("IF EXISTS");
43 let name = match extract_name_after_if_exists(parts, "SCHEDULE") {
44 None => return Ok(None),
45 Some(r) => r?,
46 };
47 return Ok(Some(NodedbStatement::Automation(
48 AutomationStmt::DropSchedule { name, if_exists },
49 )));
50 }
51 if upper.starts_with("ALTER SCHEDULE ") {
52 // ALTER SCHEDULE <name> ENABLE | DISABLE | SET CRON '<expr>'
53 let name = parts.get(2).map(|s| s.to_lowercase()).unwrap_or_default();
54 let action = parts.get(3).map(|s| s.to_uppercase()).unwrap_or_default();
55 // When action is "SET CRON", extract the quoted cron expression.
56 let cron_expr = if action == "SET" {
57 extract_quoted_cron(trimmed)
58 } else {
59 None
60 };
61 return Ok(Some(NodedbStatement::Automation(
62 AutomationStmt::AlterSchedule {
63 name,
64 action,
65 cron_expr,
66 },
67 )));
68 }
69 if upper.starts_with("SHOW SCHEDULE HISTORY ") {
70 let name = match parts.get(3) {
71 None => return Ok(None),
72 Some(s) => s.to_string(),
73 };
74 return Ok(Some(NodedbStatement::Automation(
75 AutomationStmt::ShowScheduleHistory { name },
76 )));
77 }
78 if upper == "SHOW SCHEDULES" || upper.starts_with("SHOW SCHEDULES") {
79 return Ok(Some(NodedbStatement::Automation(
80 AutomationStmt::ShowSchedules,
81 )));
82 }
83 Ok(None)
84 })()
85 .transpose()
86}
87
88/// Structural extraction for `CREATE SCHEDULE`.
89///

Callers

nothing calls this directly

Calls 6

parse_create_scheduleFunction · 0.85
extract_quoted_cronFunction · 0.85
to_stringMethod · 0.80
containsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected