1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
use diesel::{prelude::*, PgConnection}; use super::super::schema::properties; use crate::Error; #[derive(Queryable)] pub struct Property { pub id: i64, pub property_name: String, pub parent_id: i64, pub value_id: i64, pub annotation: Option<String>, } #[derive(Insertable)] #[table_name = "properties"] pub struct NewProperty { pub property_name: String, pub parent_id: i64, pub value_id: i64, pub annotation: Option<String>, } impl NewProperty { pub fn annotate(self, annotation: &str) -> Self { NewProperty { annotation: Some(annotation.to_string()), ..self } } pub fn insert(self, conn: &PgConnection) -> Result<Property, Error> { Ok(diesel::insert_into(properties::table) .values(&self) .get_result(conn)?) } }