diff options
author | tom barrett <spalf0@gmail.com> | 2019-03-28 03:33:14 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-03-28 07:24:51 -0500 |
commit | f8c446ce74329fc5844e0fc1fd82e618242196f4 (patch) | |
tree | 02319b823da4888c6d4e2faa9f482be11caad353 /src/mass.rs | |
parent | ca5ee0b32b616fb8fa5e7e44c74acecefab719c3 (diff) |
migrate and revert executable, query insert and delete test
Diffstat (limited to 'src/mass.rs')
-rw-r--r-- | src/mass.rs | 41 |
1 files changed, 41 insertions, 0 deletions
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(), + } + } } |