feat: implement to_sql trait for value enum
This commit is contained in:
@@ -33,7 +33,7 @@ fn write_attribute(
|
|||||||
transaction: &rusqlite::Transaction,
|
transaction: &rusqlite::Transaction,
|
||||||
) -> result::Result<(), FailedTo> {
|
) -> result::Result<(), FailedTo> {
|
||||||
let column = column(&attribute.value);
|
let column = column(&attribute.value);
|
||||||
let attribute_values = (&attribute.id, &entity.id, &attribute.value.to_string());
|
let attribute_values = (&attribute.id, &entity.id, &attribute.value);
|
||||||
let insert_attribute_statement =
|
let insert_attribute_statement =
|
||||||
INSERT_ATTRIBUTE_STATEMENT_TEMPLATE.replace("{column}", column);
|
INSERT_ATTRIBUTE_STATEMENT_TEMPLATE.replace("{column}", column);
|
||||||
transaction
|
transaction
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ pub mod f64_try_from_value;
|
|||||||
pub mod i32_try_from_value;
|
pub mod i32_try_from_value;
|
||||||
pub mod i64_try_from_value;
|
pub mod i64_try_from_value;
|
||||||
pub mod string_try_from_value;
|
pub mod string_try_from_value;
|
||||||
|
pub mod to_sql_value;
|
||||||
pub mod u32_try_from_value;
|
pub mod u32_try_from_value;
|
||||||
pub mod value_from_bool;
|
pub mod value_from_bool;
|
||||||
pub mod value_from_f64;
|
pub mod value_from_f64;
|
||||||
|
|||||||
13
01.workspace/heave/src/imp/to_sql_value.rs
Normal file
13
01.workspace/heave/src/imp/to_sql_value.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use crate::*;
|
||||||
|
|
||||||
|
impl rusqlite::ToSql for Value {
|
||||||
|
fn to_sql(&self) -> std::result::Result<rusqlite::types::ToSqlOutput<'_>, rusqlite::Error> {
|
||||||
|
match self {
|
||||||
|
Value::Bool(value) => Ok(rusqlite::types::ToSqlOutput::from(*value as i64)),
|
||||||
|
Value::Real(value) => Ok(rusqlite::types::ToSqlOutput::from(*value)),
|
||||||
|
Value::SignedInt(value) => Ok(rusqlite::types::ToSqlOutput::from(*value)),
|
||||||
|
Value::Text(value) => Ok(rusqlite::types::ToSqlOutput::from(value.to_string())),
|
||||||
|
Value::UnsignedInt(value) => Ok(rusqlite::types::ToSqlOutput::from(*value as i64)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user