summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml2
-rw-r--r--migrations/1_create_masses/up.sql8
-rw-r--r--src/mass.rs27
-rw-r--r--src/schema.rs8
-rw-r--r--tests/tests.rs2
6 files changed, 8 insertions, 40 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ab813f4..94540ba 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -62,7 +62,6 @@ dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 38fd525..c702e35 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,5 +11,5 @@ termion = "*"
rand = "0.6"
toml = "0.4"
clap = "2"
-diesel = {version = "1.4.2", features = ["postgres", "serde_json"]}
+diesel = {version = "1.4.2", features = ["postgres"]}
migrations_internals = "1.4.0"
diff --git a/migrations/1_create_masses/up.sql b/migrations/1_create_masses/up.sql
index 67c3b3d..f666e09 100644
--- a/migrations/1_create_masses/up.sql
+++ b/migrations/1_create_masses/up.sql
@@ -1,11 +1,5 @@
CREATE TABLE masses (
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
- pos_x FLOAT NOT NULL,
- pos_y DOUBLE PRECISION NOT NULL,
- pos_z DOUBLE PRECISION NOT NULL,
- vel_x DOUBLE PRECISION NOT NULL,
- vel_y DOUBLE PRECISION NOT NULL,
- vel_z DOUBLE PRECISION NOT NULL,
- type_data JSONB NOT NULL
+ mass VARCHAR NOT NULL
)
diff --git a/src/mass.rs b/src/mass.rs
index cbac721..aaf788f 100644
--- a/src/mass.rs
+++ b/src/mass.rs
@@ -31,24 +31,12 @@ pub struct Mass {
pub struct MassEntry {
pub id: Option<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,
+ pub mass: String,
}
impl MassEntry {
- pub fn to_mass(&self) -> Mass {
- Mass {
- position: Vector::new(self.pos_x, self.pos_y, self.pos_z),
- velocity: Vector::new(self.vel_x, self.vel_y, self.vel_z),
- mass_type: serde_json::from_str(&serde_json::to_string(&self.type_data).unwrap())
- .unwrap(),
- effects: Effects::new(),
- }
+ pub fn to_mass(&self) -> (String, Mass) {
+ (self.name.clone(), serde_json::from_str(&self.mass).unwrap())
}
}
@@ -331,14 +319,7 @@ impl Mass {
MassEntry {
id: None,
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(),
+ mass: serde_json::to_string(&self).unwrap(),
}
}
}
diff --git a/src/schema.rs b/src/schema.rs
index 71abe49..c258603 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -2,12 +2,6 @@ table! {
masses (id) {
id -> Nullable<Integer>,
name -> Varchar,
- pos_x -> Double,
- pos_y -> Double,
- pos_z -> Double,
- vel_x -> Double,
- vel_y -> Double,
- vel_z -> Double,
- type_data -> Jsonb,
+ mass -> Varchar,
}
}
diff --git a/tests/tests.rs b/tests/tests.rs
index 781e365..7d7449c 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -553,7 +553,7 @@ mod tests {
.load::<MassEntry>(&connection)
.expect("Cannot filter");
- assert!(mass.position.x == db_mass[0].pos_x);
+ assert!(mass.position.x == db_mass[0].to_mass().1.position.x);
diesel::delete(db_masses.filter(dsl::name.eq(name)))
.execute(&connection)