(v: Value)
| 252 | } |
| 253 | |
| 254 | fn ndb_to_sql_value(v: Value) -> SqlValue { |
| 255 | match v { |
| 256 | Value::Null => SqlValue::Null, |
| 257 | Value::Bool(b) => SqlValue::Bool(b), |
| 258 | Value::Integer(i) => SqlValue::Int(i), |
| 259 | Value::Float(f) => SqlValue::Float(f), |
| 260 | Value::String(s) => SqlValue::String(s), |
| 261 | Value::Bytes(b) => SqlValue::Bytes(b), |
| 262 | Value::Array(a) => SqlValue::Array(a.into_iter().map(ndb_to_sql_value).collect()), |
| 263 | // TZ-aware DateTime → Timestamptz; naive → Timestamp. |
| 264 | Value::DateTime(dt) => SqlValue::Timestamptz(dt), |
| 265 | Value::NaiveDateTime(dt) => SqlValue::Timestamp(dt), |
| 266 | Value::Uuid(s) | Value::Ulid(s) | Value::Regex(s) => SqlValue::String(s), |
| 267 | Value::Duration(d) => SqlValue::String(d.to_human()), |
| 268 | Value::Decimal(d) => SqlValue::Decimal(d), |
| 269 | // Geometry and Object values are serialized to JSON strings so that |
| 270 | // nested function calls like ST_Distance(ST_Point(...), ST_Point(...)) |
| 271 | // survive the SqlValue round-trip. The geo evaluator's geom_arg helper |
| 272 | // recovers Geometry from a GeoJSON string; Object results (e.g. from |
| 273 | // ST_GeoHashDecode) reach the client as a JSON-encoded string column. |
| 274 | Value::Geometry(g) => sonic_rs::to_string(&g) |
| 275 | .map(SqlValue::String) |
| 276 | .unwrap_or(SqlValue::Null), |
| 277 | Value::Object(map) => sonic_rs::to_string(&map) |
| 278 | .map(SqlValue::String) |
| 279 | .unwrap_or(SqlValue::Null), |
| 280 | // Structured and opaque types collapse to Null — callers that |
| 281 | // need these go through the runtime expression path, not folding. |
| 282 | Value::Set(_) | Value::Range { .. } | Value::Record { .. } | Value::ArrayCell(_) => { |
| 283 | SqlValue::Null |
| 284 | } |
| 285 | // Value is #[non_exhaustive]; future variants collapse to Null in the |
| 286 | // constant-folding path — runtime expression evaluation handles them. |
| 287 | _ => SqlValue::Null, |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | #[cfg(test)] |
| 292 | mod tests { |
no test coverage detected