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

Function parse_set_idle_timeout

nodedb-sql/src/ddl_ast/parse/database/alter.rs:115–144  ·  view source on GitHub ↗
(parts: &[&str])

Source from the content-addressed store, hash-verified

113}
114
115fn parse_set_idle_timeout(parts: &[&str]) -> Result<AlterDatabaseOperation, SqlError> {
116 let eq = parts.get(5).copied().unwrap_or("");
117 if eq != "=" {
118 return Err(SqlError::Parse {
119 detail: format!("ALTER DATABASE SET IDLE_TIMEOUT requires '=', got '{eq}'"),
120 });
121 }
122 let raw = parts.get(6).copied().ok_or_else(|| SqlError::Parse {
123 detail: "ALTER DATABASE SET IDLE_TIMEOUT requires a non-negative integer (seconds)".into(),
124 })?;
125 let secs = raw
126 .trim_matches('\'')
127 .trim_matches('"')
128 .parse::<u64>()
129 .map_err(|_| SqlError::Parse {
130 detail: format!(
131 "ALTER DATABASE SET IDLE_TIMEOUT: invalid value '{raw}', expected non-negative integer"
132 ),
133 })?;
134 if secs > MAX_IDLE_TIMEOUT_SECS {
135 return Err(SqlError::Parse {
136 detail: format!(
137 "ALTER DATABASE SET IDLE_TIMEOUT: {secs}s exceeds maximum {MAX_IDLE_TIMEOUT_SECS}s ({} days). \
138 Use 0 to disable the timeout entirely.",
139 MAX_IDLE_TIMEOUT_SECS / 86_400
140 ),
141 });
142 }
143 Ok(AlterDatabaseOperation::SetIdleTimeout(secs))
144}
145
146#[cfg(test)]
147mod tests {

Callers 1

parse_setFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected