How to write back to databases

Audience: Developers making Sapho micro apps

For micro apps that are connected directly to a database, Sapho supports all CRUD actions. For any updates or inserts, Sapho will ensure that no data conflicts occur during the transaction.

Sapho makes it easy to set up database write-backs in your micro apps. The instructions below cover the use cases of creating and updating records.

  1. In the Add Page wizard, select Single Page recipes and add a form to your micro app (alternatively you can use a multi-page recipe that ends with a form). Click NEXT.
    DB_1.png
  2. Select Editable Form and click NEXT.
    DB_2.png
  3. Select the fields from the database you would like the user to be able to edit.
    DB_3.png
  4. Click NEXT. Sapho automatically creates the page including a button component with its Action property set to Add / Update.
    DB_4.png
    Two label fields are provided for buttons with this type of action.
    DB_5.png
    Sapho will automatically display the correct text depending on what mode the page is in at runtime. The page mode is determined by how the user navigates to that particular page:
    • Add Mode - The user goes directly to the page from a button, i.e. the page is rendered without Sapho having an ID for an existing record. Please note that you must have auto-increment set on your primary key in order for inserts from Sapho to work properly.
      DB_6.png
    • Edit Mode - The user goes to the page from some list or feed card, i.e. there is an existing record in the database and Sapho knows the ID.
      DB_7.png