summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/client.rs6
-rw-r--r--src/bin/migrate.rs5
-rw-r--r--src/lib.rs3
-rw-r--r--src/mass.rs31
-rw-r--r--src/schema.rs2
5 files changed, 22 insertions, 25 deletions
diff --git a/src/bin/client.rs b/src/bin/client.rs
index cbc7302..a91c2dc 100644
--- a/src/bin/client.rs
+++ b/src/bin/client.rs
@@ -1,11 +1,11 @@
+#[macro_use]
+extern crate serde;
+
extern crate clap;
extern crate serde_json;
extern crate space;
extern crate toml;
-#[macro_use]
-extern crate serde_derive;
-
use clap::{App, SubCommand};
use std::fs::File;
use std::io;
diff --git a/src/bin/migrate.rs b/src/bin/migrate.rs
index 8d269a4..f19a766 100644
--- a/src/bin/migrate.rs
+++ b/src/bin/migrate.rs
@@ -6,9 +6,4 @@ use space::math::get_db_url;
fn main() {
let connection = PgConnection::establish(&get_db_url()).expect("Cannot connect");
migrations_internals::run_pending_migrations(&connection).expect("Cannot run migrations");
-
- //migrations_internals::revert_latest_migration(&connection)
- // .expect("Cannot revert migrations");
- //migrations_internals::revert_latest_migration(&connection)
- // .expect("Cannot revert migrations");
}
diff --git a/src/lib.rs b/src/lib.rs
index 26dee5c..b6cf4bc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,6 @@
#[macro_use]
-extern crate serde_derive;
+extern crate serde;
+
#[macro_use]
extern crate diesel;
diff --git a/src/mass.rs b/src/mass.rs
index ed859a4..cbac721 100644
--- a/src/mass.rs
+++ b/src/mass.rs
@@ -26,9 +26,10 @@ pub struct Mass {
pub effects: Effects,
}
-#[derive(Queryable)]
+#[derive(Queryable, Insertable)]
+#[table_name = "db_masses"]
pub struct MassEntry {
- pub id: i32,
+ pub id: Option<i32>,
pub name: String,
pub pos_x: f64,
pub pos_y: f64,
@@ -39,17 +40,16 @@ pub struct MassEntry {
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,
+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(),
+ }
+ }
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
@@ -327,8 +327,9 @@ impl Mass {
}
}
- pub fn to_new_mass_entry(&self, name: String) -> NewMassEntry {
- NewMassEntry {
+ pub fn to_mass_entry(&self, name: String) -> MassEntry {
+ MassEntry {
+ id: None,
name,
pos_x: self.position.x,
pos_y: self.position.y,
diff --git a/src/schema.rs b/src/schema.rs
index 2bb43ed..71abe49 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -1,6 +1,6 @@
table! {
masses (id) {
- id -> Integer,
+ id -> Nullable<Integer>,
name -> Varchar,
pos_x -> Double,
pos_y -> Double,