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

Function quote_string_literal

nodedb-client/src/sql_escape/literal.rs:12–15  ·  view source on GitHub ↗

SQL string-literal escaping. Render a `&str` as a SQL string literal: single-quote-doubled and wrapped in single quotes. Matches `standard_conforming_strings=on` behavior (PG 9.1+ default), the only mode the server runs in. Centralizes the escape so call sites can't drift into raw `format!`s without going through it — every `'foo'` written into a SQL string inside this crate goes through here.

(s: &str)

Source from the content-addressed store, hash-verified

10/// without going through it — every `'foo'` written into a SQL string
11/// inside this crate goes through here.
12pub(crate) fn quote_string_literal(s: &str) -> String {
13 let escaped = s.replace('\'', "''");
14 format!("'{escaped}'")
15}
16
17#[cfg(test)]
18mod tests {

Callers 9

passes_through_jsonFunction · 0.85
render_sql_literalFunction · 0.85
graph_traverse_implMethod · 0.85
build_graph_stats_sqlFunction · 0.85
text_search_implMethod · 0.85

Calls 1

replaceMethod · 0.80

Tested by 1

passes_through_jsonFunction · 0.68