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

Function detect

nodedb/src/control/backup/detect.rs:18–34  ·  view source on GitHub ↗

Returns Some(intent) if the SQL is one of the recognised wire-COPY shapes. Tokenisation is whitespace-only and case-insensitive on keywords.

(sql: &str)

Source from the content-addressed store, hash-verified

16/// Returns Some(intent) if the SQL is one of the recognised wire-COPY shapes.
17/// Tokenisation is whitespace-only and case-insensitive on keywords.
18pub fn detect(sql: &str) -> Option<CopyIntent> {
19 let trimmed = sql.trim().trim_end_matches(';').trim();
20 let upper = trimmed.to_ascii_uppercase();
21
22 // Quick reject: every recognised shape starts with COPY.
23 if !upper.starts_with("COPY ") && !upper.starts_with("COPY\t") {
24 return None;
25 }
26
27 if let Some(intent) = match_backup(trimmed, &upper) {
28 return Some(intent);
29 }
30 if let Some(intent) = match_restore(trimmed, &upper) {
31 return Some(intent);
32 }
33 None
34}
35
36fn match_backup(sql: &str, upper: &str) -> Option<CopyIntent> {
37 // Pattern: COPY ( BACKUP TENANT <id> ) TO STDOUT

Callers 6

runtime_detects_featuresFunction · 0.85
create_functionFunction · 0.85
execute_single_sqlMethod · 0.85
execute_preparedMethod · 0.85
parse_sqlMethod · 0.85
runMethod · 0.85

Calls 2

match_backupFunction · 0.85
match_restoreFunction · 0.85

Tested by 1

runtime_detects_featuresFunction · 0.68