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

Function render_sql_literal

nodedb-client/src/remote/sql.rs:136–147  ·  view source on GitHub ↗

Render a single `Value` as a SQL literal. Strings are single-quote escaped; numeric / boolean / null variants are formatted directly. Returns `Err` for variants the SQL literal layer cannot represent.

(v: &Value)

Source from the content-addressed store, hash-verified

134/// escaped; numeric / boolean / null variants are formatted directly.
135/// Returns `Err` for variants the SQL literal layer cannot represent.
136fn render_sql_literal(v: &Value) -> NodeDbResult<String> {
137 match v {
138 Value::Null => Ok("NULL".into()),
139 Value::Bool(b) => Ok(if *b { "TRUE".into() } else { "FALSE".into() }),
140 Value::Integer(i) => Ok(i.to_string()),
141 Value::Float(f) => Ok(f.to_string()),
142 Value::String(s) => Ok(quote_string_literal(s)),
143 other => Err(NodeDbError::storage(format!(
144 "metadata filter value cannot be rendered as a SQL literal: {other:?}"
145 ))),
146 }
147}
148
149/// Translate trait-level `&[Value]` parameters into owned, `ToSql`-
150/// compatible boxes for `tokio_postgres`. Returns one boxed parameter

Calls 2

quote_string_literalFunction · 0.85
to_stringMethod · 0.80

Tested by 1