From 7e5592f0d186dde6e3e10be51efce2bdfc7483d0 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 26 Sep 2018 18:43:53 +0200 Subject: [PATCH] fix(postgres): Minor fixes in Postgres queries and handling --- finito-postgres/Cargo.toml | 3 +++ finito-postgres/src/lib.rs | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/finito-postgres/Cargo.toml b/finito-postgres/Cargo.toml index c9f8476db..f32a30d5b 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 6e1815a69..80200f8a4 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(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(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(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(conn: &C, // And finally the state is updated: update_state(&tx, id, &new_state).expect("TODO"); + tx.commit().expect("TODO"); + Ok(new_state) }