"""Shared utility helpers.""" def escape_like(value: str) -> str: """Escape SQL LIKE wildcard characters (``%`` and ``_``). Prevents user-supplied search terms from being interpreted as LIKE pattern metacharacters when used with SQLAlchemy's ``ilike``/``like`` methods. Usage:: from app.utils import escape_like query.filter(Model.name.ilike(f"%{escape_like(term)}%")) """ return ( value .replace("\\", "\\\\") .replace("%", "\\%") .replace("_", "\\_") )