db transactions #75

Closed
opened 2021-10-14 02:46:15 -04:00 by jake · 0 comments
Owner

create some sort of way to use db transactions to allow rollbacks in case of failure mid-activity. something like create PostgresTransaction that actually impls EntityGateway and PostgresGateway just calls through to it

impl EntityGateway for PostgresTransaction {
  ...
}




impl PostgresGateway {
    fn transaction() -> PostgresTransaction {
      ...
    }
}

or something else like👍:

impl PostgresGateway {
  fn transaction(&mut self, cb: FnMut(&mut PostgresGateway) -> Result<T, E>) -> Result<T, E> {
    self.do_transaction_begin();
    let r =  cb(self)?;
    self.do_commit();
    Ok(r)
  }
}



let db = PostgresGateway::new();
db.transaction(|db| {
  db.do_a_thing()?;
  db.do_b_thing()?;
});

create some sort of way to use db transactions to allow rollbacks in case of failure mid-activity. something like create `PostgresTransaction` that actually impls `EntityGateway` and `PostgresGateway` just calls through to it ``` impl EntityGateway for PostgresTransaction { ... } impl PostgresGateway { fn transaction() -> PostgresTransaction { ... } } ``` or something else like👍: ``` impl PostgresGateway { fn transaction(&mut self, cb: FnMut(&mut PostgresGateway) -> Result<T, E>) -> Result<T, E> { self.do_transaction_begin(); let r = cb(self)?; self.do_commit(); Ok(r) } } let db = PostgresGateway::new(); db.transaction(|db| { db.do_a_thing()?; db.do_b_thing()?; }); ```
jake added the
nice to have
label 2021-12-30 16:36:51 -05:00
jake closed this issue 2022-09-20 20:35:19 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jake/elseware#75
No description provided.