pub fn limit_clause(limit: u64) -> (&'static str, Option<i64>)Expand description
Builds the LIMIT clause fragment (with leading space) and its bind value for the
“0 means unlimited” convention used across list-style queries (SessionStore::list,
list_acp_sessions, list_owned_sessions, list_agent_sessions, …).
limit == 0 returns ("", None): the caller omits the LIMIT clause entirely.
This is the only cross-backend-safe way to express “unlimited” — LIMIT -1, the
SQLite-only convenience sentinel used before this helper existed, is rejected by
PostgreSQL at execution time (ERROR: LIMIT must not be negative), and binding a
NULL in its place is rejected by SQLite (SQLITE_MISMATCH), so neither backend
accepts a single placeholder value that means “no limit”.
Any other value returns (" LIMIT ?", Some(limit)); the caller appends the fragment
to the query text and, only when the returned bind value is Some, adds a matching
.bind() call.
§Examples
use zeph_db::limit_clause;
assert_eq!(limit_clause(0), ("", None));
assert_eq!(limit_clause(10), (" LIMIT ?", Some(10)));