chain-builder 3.1.0

A typed, dialect-aware SQL query builder for Rust (PostgreSQL/MySQL/SQLite).
Documentation
//! `LIKE`-pattern escaping helper.

/// Escape `\`, `%`, and `_` so user input matches **literally** inside a
/// `LIKE`/`ILIKE` pattern. The caller still wraps the result in `%…%` /
/// `…%` as needed — and the result stays a **bind value** (pass it through
/// `where_like`/a placeholder as usual; never splice it into the SQL text).
///
/// Backslash is escaped first (order matters), then `%` and `_`:
///
/// ```
/// use chain_builder::escape_like;
/// assert_eq!(escape_like("100%_a\\b"), "100\\%\\_a\\\\b");
/// assert_eq!(format!("%{}%", escape_like("50%")), "%50\\%%");
/// ```
///
/// # Portability caveat
///
/// What `\` means inside a `LIKE` pattern is dialect-defined: Postgres and
/// MySQL treat backslash as the default escape character, but **SQLite has
/// no default escape character at all**. For fully portable literal
/// matching, pair the escaped pattern with an explicit `ESCAPE '\'` clause
/// via `where_raw` (on MySQL write the literal as `ESCAPE '\\'`). See the
/// search-pattern chapter of the book for the full recipe.
///
/// Covers the metacharacters of the supported dialects (Postgres, MySQL,
/// SQLite). `[` — a `LIKE` metacharacter on SQL Server only — is **not**
/// escaped.
pub fn escape_like(input: &str) -> String {
    input
        .replace('\\', "\\\\")
        .replace('%', "\\%")
        .replace('_', "\\_")
}