use rusqlite::types::Type;
use serde::de::DeserializeOwned;
use crate::bridge_protocol::ThreadSummary;
pub(super) fn decode_json_row<T: DeserializeOwned>(raw: String) -> rusqlite::Result<T> {
serde_json::from_str(&raw)
.map_err(|error| rusqlite::Error::FromSqlConversionFailure(0, Type::Text, Box::new(error)))
}
pub(super) fn decode_thread_row(
raw: String,
note: Option<String>,
archived: i64,
) -> rusqlite::Result<ThreadSummary> {
let mut thread: ThreadSummary = decode_json_row(raw)?;
thread.note = note;
thread.archived = archived != 0;
Ok(thread)
}