use crate::error::{Error, Result};
use crate::row::FromRow;
use rusqlite::ToSql;
use rusqlite::types::{ToSqlOutput, Value};
pub fn to_owned_value<T: ToSql + ?Sized>(t: &T) -> Result<Value> {
match t.to_sql()? {
ToSqlOutput::Borrowed(vr) => Ok(vr.into()),
ToSqlOutput::Owned(v) => Ok(v),
other => Err(Error::Internal(format!(
"지원하지 않는 ToSqlOutput 변형: {other:?} — 비동기 경로에서 사용 불가"
))),
}
}
pub fn outputs_to_values(outs: Vec<ToSqlOutput<'_>>) -> Result<Vec<Value>> {
outs.into_iter()
.map(|o| match o {
ToSqlOutput::Borrowed(vr) => Ok(vr.into()),
ToSqlOutput::Owned(v) => Ok(v),
other => Err(Error::Internal(format!(
"지원하지 않는 ToSqlOutput 변형: {other:?} — 비동기 경로에서 사용 불가"
))),
})
.collect()
}
pub trait Entity: FromRow {
const TABLE: &'static str;
const DDL: &'static [&'static str];
const COLUMNS: &'static str;
const COLUMNS_META: &'static [crate::database::ColumnMeta];
const MULTI_INSTANCE: bool = false;
}
pub trait Insertable: Entity {
const INSERT_COLUMNS: &'static str;
const INSERT_PLACEHOLDERS: &'static str;
const INSERT_COLUMNS_KEEP_PK: &'static str;
const INSERT_PLACEHOLDERS_KEEP_PK: &'static str;
fn insert_params(&self) -> crate::Result<Vec<ToSqlOutput<'_>>>;
fn insert_params_keep_pk(&self) -> crate::Result<Vec<ToSqlOutput<'_>>>;
}