How to combine several queries into one function?

Basically, my question is about an approach. Currently I have a three queries which do these:

  1. Create sale entry in DB
  2. Create sale item in DB with sale entry id from the first query
  3. Update stock table with a new amount for each sale item

I call of these queries one by one from Run Script action of the Button. My question is: can I have a special function which will combine all of these queries or my approach is already good enough?

I'm really new to Retool maybe I'm missing something else.

I've decided to use PLSQL functions. Looks like its a proper way to handle all of these queries

It looks like you are trying to insert a parent record, then one or more child records, and then make an update to a third table. I've just seen and responded to a similar-ish question here:

You can certainly write PL/SQL functions in your DB, or you can try something like the linked question as well, triggering each subsequent step from the success of the one before (or in a JS block).