From f8c446ce74329fc5844e0fc1fd82e618242196f4 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Thu, 28 Mar 2019 03:33:14 -0500 Subject: migrate and revert executable, query insert and delete test --- src/mass.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/mass.rs') diff --git a/src/mass.rs b/src/mass.rs index 820173f..ed859a4 100644 --- a/src/mass.rs +++ b/src/mass.rs @@ -15,6 +15,7 @@ use crate::modules::navigation::Navigation; use crate::modules::refinery::Refinery; use crate::modules::tractorbeam::Tractorbeam; use crate::modules::types::ModuleType; +use crate::schema::masses as db_masses; use crate::storage::Storage; #[derive(Serialize, Deserialize, Debug, Clone)] @@ -25,6 +26,32 @@ pub struct Mass { pub effects: Effects, } +#[derive(Queryable)] +pub struct MassEntry { + pub id: i32, + pub name: String, + pub pos_x: f64, + pub pos_y: f64, + pub pos_z: f64, + pub vel_x: f64, + pub vel_y: f64, + pub vel_z: f64, + pub type_data: serde_json::Value, +} + +#[derive(Insertable)] +#[table_name = "db_masses"] +pub struct NewMassEntry { + pub name: String, + pub pos_x: f64, + pub pos_y: f64, + pub pos_z: f64, + pub vel_x: f64, + pub vel_y: f64, + pub vel_z: f64, + pub type_data: serde_json::Value, +} + #[derive(Serialize, Deserialize, Debug, Clone, Default)] pub struct Effects { acceleration: Vector, @@ -299,4 +326,18 @@ impl Mass { _ => 0, } } + + pub fn to_new_mass_entry(&self, name: String) -> NewMassEntry { + NewMassEntry { + name, + pos_x: self.position.x, + pos_y: self.position.y, + pos_z: self.position.z, + vel_x: self.velocity.x, + vel_y: self.velocity.y, + vel_z: self.velocity.z, + type_data: serde_json::from_str(&serde_json::to_string(&self.mass_type).unwrap()) + .unwrap(), + } + } } -- cgit v1.2.3