about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2018-09-26T16·43+0200
committerVincent Ambo <mail@tazj.in>2018-09-26T16·43+0200
commit7e5592f0d186dde6e3e10be51efce2bdfc7483d0 (patch)
tree33e744f6556cd350fbbd699bfec2fa22f8597d96
parent6254d056204b41b346367f9f03a4407b6c2a1a1a (diff)
fix(postgres): Minor fixes in Postgres queries and handling
-rw-r--r--finito-postgres/Cargo.toml3
-rw-r--r--finito-postgres/src/lib.rs9
2 files changed, 9 insertions, 3 deletions
diff --git a/finito-postgres/Cargo.toml b/finito-postgres/Cargo.toml
index c9f8476dbdc6..f32a30d5be3f 100644
--- a/finito-postgres/Cargo.toml
+++ b/finito-postgres/Cargo.toml
@@ -19,3 +19,6 @@ features = [ "v4" ]
 
 [dependencies.finito]
 path = "../finito-core"
+
+[dev-dependencies.finito-door]
+path = "../finito-door"
diff --git a/finito-postgres/src/lib.rs b/finito-postgres/src/lib.rs
index 6e1815a69fa1..80200f8a43cd 100644
--- a/finito-postgres/src/lib.rs
+++ b/finito-postgres/src/lib.rs
@@ -67,6 +67,7 @@ struct EventT {
 
 /// This enum represents the possible statuses an action can be in.
 #[derive(Debug, ToSql, FromSql)]
+#[postgres(name = "actionstatus")]
 enum ActionStatus {
     /// The action was requested but has not run yet.
     Pending,
@@ -195,7 +196,7 @@ fn insert_action<C, S>(conn: &C,
     S: FSM,
     S::Action: Serialize {
     let query = r#"
-      INSERT INTO actions (id, fsm, fsm_id, event_id, action, status)
+      INSERT INTO actions (id, fsm, fsm_id, event_id, content, status)
       VALUES ($1, $2, $3, $4, $5, $6)
     "#;
 
@@ -239,7 +240,7 @@ pub fn get_machine<C, S>(conn: &C,
     C: GenericConnection,
     S: FSM + DeserializeOwned {
     let query = r#"
-      SELECT (id, created, fsm, state) FROM machines WHERE id = $1
+      SELECT id, created, fsm, state FROM machines WHERE id = $1
     "#;
 
     // If the machine is being fetched in the context of a
@@ -252,7 +253,7 @@ pub fn get_machine<C, S>(conn: &C,
 
     let rows = conn.query(&query, &[&id.to_uuid()]).expect("TODO");
     let mut machines = rows.into_iter().map(|row| MachineT {
-        id: row.get(0),
+        id: id.to_uuid(),
         created: row.get(1),
         fsm: row.get(2),
         state: row.get(3),
@@ -300,5 +301,7 @@ pub fn advance<C, S>(conn: &C,
 
     // And finally the state is updated:
     update_state(&tx, id, &new_state).expect("TODO");
+    tx.commit().expect("TODO");
+
     Ok(new_state)
 }