mirror of
https://github.com/element-hq/synapse.git
synced 2026-08-14 20:10:26 +00:00
Introduce the Python<->Postgres value-mapping layer that the forthcoming Rust DBAPI2 backend will build on, plus the module scaffolding to hang it off (`synapse_rust.database.postgres`). `PgValue` is an owned representation of a bound parameter that implements `tokio_postgres::types::ToSql`, encoding into Postgres' binary wire format according to the column type from the prepared statement (so a single Python `int` becomes INT2/INT4/INT8 as appropriate, with range checks). `PythonPgFromSql` is the decode counterpart, turning a column's wire bytes back into the natural Python object (and SQL NULL into `None`). The two `accepts` lists are kept in sync via tests. The `value` submodule is exposed as `pub` for now so its not-yet-consumed public items don't trip clippy's `dead_code` lint; later changes that wire it into the cursor/connection code tighten that back up. Covers int / float / bool / str / bytes / None; lists and richer types (json, decimal, timestamps) are left to a follow-up. The unit tests exercise the whole mapping without a live Postgres server, including the float4 lossy narrowing, integer width boundaries, the WrongType and out-of-range paths, and the unsupported/non-UTF-8 decode errors. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>