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

Function strip_system_time_as_of

nodedb-sql/src/parser/preprocess/temporal.rs:125–145  ·  view source on GitHub ↗

Match `FOR SYSTEM_TIME AS OF ` case-insensitively and strip it.

(sql: &str)

Source from the content-addressed store, hash-verified

123
124/// Match `FOR SYSTEM_TIME AS OF <integer>` case-insensitively and strip it.
125fn strip_system_time_as_of(sql: &str) -> Result<Option<(String, i64)>, TemporalParseError> {
126 let Some(start) = keyword_position_outside_literals(sql, "FOR SYSTEM_TIME") else {
127 return Ok(None);
128 };
129 // Locate `AS OF` after the keyword.
130 let after_kw = start + "FOR SYSTEM_TIME".len();
131 let tail_upper = sql[after_kw..].to_uppercase();
132 let Some(_as_of_rel) = tail_upper.trim_start().strip_prefix("AS OF") else {
133 return Err(TemporalParseError(
134 "FOR SYSTEM_TIME must be followed by AS OF <ms>".into(),
135 ));
136 };
137 let leading_ws = sql[after_kw..].len() - sql[after_kw..].trim_start().len();
138 let as_of_abs = after_kw + leading_ws + "AS OF".len();
139 let (ms, end_abs) = parse_trailing_i64(sql, as_of_abs)?;
140 let mut out = String::with_capacity(sql.len());
141 out.push_str(&sql[..start]);
142 out.push(' ');
143 out.push_str(&sql[end_abs..]);
144 Ok(Some((out, ms)))
145}
146
147/// Match `__system_as_of__(<int>)` anywhere in the statement and strip the
148/// call by replacing it with the literal `TRUE` so the surrounding

Callers 1

extractFunction · 0.85

Calls 5

TemporalParseErrorClass · 0.85
parse_trailing_i64Function · 0.85
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected