Transactions using the Firebase Integration

HI @anthonys,

I updated the docs with an up to date transaction example.
Basically, what you do is give a function to the run_transaction method and this function will then be executed as a transaction.
Docs

new_order_dict = {'name':'my example order'}

def add_new_order(transaction):
  #get the document which stores the order ids
  order_id_ref = fs.doc(fs.db,'ids','current_order_number')
  order_id_doc = transaction.get(order_id_ref)
  	
  #calculate the next free order id and write it to the dict
  next_order_id = order_id_doc.data()['count'] + 1
  new_order_dict['id'] = next_order_id
  
  #save new order document
  new_order_ref = fs.doc(fs.db,'orders') 
  transaction.set(new_order_ref,new_order_dict)
  
  #increment the order id for the next order
  transaction.update(order_id_ref,{'count': fs.increment(1)})


#Run the above database operations in a transaction     
fs.run_transaction(add_new_order)```
2 Likes