| 317 | } |
| 318 | |
| 319 | pub fn convert(&self, converter_idx: u8, value: &rusqlite::types::Value) -> Result<Vec<u8>, rusqlite::Error> { |
| 320 | if let Some(converter) = self.converters.get(converter_idx as usize) { |
| 321 | converter(value) |
| 322 | } else { |
| 323 | // Fallback to text conversion |
| 324 | match value { |
| 325 | rusqlite::types::Value::Text(s) => Ok(s.as_bytes().to_vec()), |
| 326 | rusqlite::types::Value::Integer(i) => { |
| 327 | let mut buf = itoa::Buffer::new(); |
| 328 | Ok(buf.format(*i).as_bytes().to_vec()) |
| 329 | }, |
| 330 | rusqlite::types::Value::Real(r) => Ok(r.to_string().as_bytes().to_vec()), |
| 331 | rusqlite::types::Value::Null => Ok(Vec::new()), |
| 332 | _ => Ok("".as_bytes().to_vec()), |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | pub fn convert_binary(&self, value: &rusqlite::types::Value, type_oid: i32) -> Result<Vec<u8>, rusqlite::Error> { |
| 338 | (self.binary_converter)(value, type_oid) |