fermyon / spin

Spin is the open source developer tool for building and running serverless applications powered by WebAssembly.
https://developer.fermyon.com/spin
Apache License 2.0
5.47k stars 255 forks source link

Add first-class transaction support for DBMS in Spin SDKs #2286

Open ThorstenHans opened 8 months ago

ThorstenHans commented 8 months ago

It would be really handy to have first-class support for transactions when interacting with DBMS like PostgreSQL or MySQL.

As of today it is possible to concat multiple commands and surround those with BEGIN and COMMIT to use transactions. Although this works, it comes at the cost of ending up with longer TSQL statements.

In contrast, having first-class support for transactions, would result in

See the following (pseudo-code) for illustration.

// ...
let connection = Connection::open(connection_string)?;
let tx = connection::begin_transaction();

let res1 = tx.execute("MY 1ST COMMAND", &params);
let res2 = tx.execute("MY 2ND COMMAND", &params);

match tx.commit() {
  Ok(res) => ,   // ...
  Err(e) => tx.rollback(),      // ...
}
lann commented 8 months ago

I think we should track this sort of thing per-language; some language ecosystems (like Python's) do not typically represent transactions as separate resources, and those languages that do often have existing patterns or interfaces that should be targeted (like Go, where we implement the standard interface but currently don't support transactions).