fix(postgres): Minor fixes in Postgres queries and handling
This commit is contained in:
parent
6254d05620
commit
7e5592f0d1
2 changed files with 9 additions and 3 deletions
|
@ -19,3 +19,6 @@ features = [ "v4" ]
|
||||||
|
|
||||||
[dependencies.finito]
|
[dependencies.finito]
|
||||||
path = "../finito-core"
|
path = "../finito-core"
|
||||||
|
|
||||||
|
[dev-dependencies.finito-door]
|
||||||
|
path = "../finito-door"
|
||||||
|
|
|
@ -67,6 +67,7 @@ struct EventT {
|
||||||
|
|
||||||
/// This enum represents the possible statuses an action can be in.
|
/// This enum represents the possible statuses an action can be in.
|
||||||
#[derive(Debug, ToSql, FromSql)]
|
#[derive(Debug, ToSql, FromSql)]
|
||||||
|
#[postgres(name = "actionstatus")]
|
||||||
enum ActionStatus {
|
enum ActionStatus {
|
||||||
/// The action was requested but has not run yet.
|
/// The action was requested but has not run yet.
|
||||||
Pending,
|
Pending,
|
||||||
|
@ -195,7 +196,7 @@ fn insert_action<C, S>(conn: &C,
|
||||||
S: FSM,
|
S: FSM,
|
||||||
S::Action: Serialize {
|
S::Action: Serialize {
|
||||||
let query = r#"
|
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)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
@ -239,7 +240,7 @@ pub fn get_machine<C, S>(conn: &C,
|
||||||
C: GenericConnection,
|
C: GenericConnection,
|
||||||
S: FSM + DeserializeOwned {
|
S: FSM + DeserializeOwned {
|
||||||
let query = r#"
|
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
|
// 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 rows = conn.query(&query, &[&id.to_uuid()]).expect("TODO");
|
||||||
let mut machines = rows.into_iter().map(|row| MachineT {
|
let mut machines = rows.into_iter().map(|row| MachineT {
|
||||||
id: row.get(0),
|
id: id.to_uuid(),
|
||||||
created: row.get(1),
|
created: row.get(1),
|
||||||
fsm: row.get(2),
|
fsm: row.get(2),
|
||||||
state: row.get(3),
|
state: row.get(3),
|
||||||
|
@ -300,5 +301,7 @@ pub fn advance<C, S>(conn: &C,
|
||||||
|
|
||||||
// And finally the state is updated:
|
// And finally the state is updated:
|
||||||
update_state(&tx, id, &new_state).expect("TODO");
|
update_state(&tx, id, &new_state).expect("TODO");
|
||||||
|
tx.commit().expect("TODO");
|
||||||
|
|
||||||
Ok(new_state)
|
Ok(new_state)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue