Skip to main content

Create and modify data

Introduction#

  1. Object are first created locally
  2. Object can then be persisted in Olympe Database
  3. Properties values can be updated
  4. Relations can be created between objects
  5. Data operations can be (optionally) grouped into a Transaction create_datas)

There are other actions to craete/modify data:

  • Delete Object
  • Detach All Relations
  • Detach Relation
  • ...

See transaction module documentation page for more details.

Best practices#

Create Constructors: Actions to create Objects (e.g. Create Note) with inputs for attributes (content, summary, …). Constructors call to “Persist” Action.

Create Getters: Functions to get all properties of an Object (e.g. Note’s Attributes) with the object as input (the note) and attributes as outputs (content, summary, …)

Create Setters: Actions to update an Object ( e.g. Set Note’s Content) with the object (the note) and the attribute value (content) as inputs

Exercise 10 – Notes Constructor#

The goal of this exercise is to define a reusable action which creates a new Note (aka a Note constructor).

  1. Go to Folder “Data”
  2. Open "Notes Data Model"
  3. On "Note" model, click on the 3 dots icon to open the contextual menu
  4. Select "Generate helper bricks"
  5. Select folder "Data" and click on "Save to Data" button
  6. Select "Constructor"
  7. Below constructor select properties "Content" and "Summary" (see screenshot below)
  8. Click on continue
  9. Once the bricks are generated, click on close
  10. Go back to Folder "Data" => A new brick named "Create note" was generated. exercise_10_result

Exercise 11 – Get Notes Attributes#

The goal of this exercise is to define a reusable function which returns the attributes of a Note object. In this case, we will only return

  1. Go to Folder “Data”
  2. Open "Notes Data Model"
  3. On "Note" model, click on the 3 dots icon to open the contextual menu
  4. Select "Generate helper bricks"
  5. Select folder "Data" and click on "Save to Data" button
  6. Select "Getter" (see screenshot below)
  7. Click on continue
  8. Once the bricks are generated, click on close
  9. Go back to Folder "Data" => A new brick named "Get Note's attributes" was generated.

exercise_11_result

Exercise 12 – New Note screen#

The goal of this exercise is to define a screen which creates a new note. exercise_12_result

  1. Go to Screen “New Note”
  2. Rename Event “New Header On left button click” to “To home screen” (=> Context editor)
  3. Add a Text Field named “Summary Field”
    • Placeholder = “Summary”
  4. Add a Text Area named “Content Field”
    • Placeholder = “Content”
  5. Add a Button named “Create Button”
    • Text to “Create”
  6. Group components added before
  7. Add an Action triggered by “Create Button” on click event which:
    • Create a new note from values from “Summary Field” and “Content Field”
    • Dispatch the event “To home screen”

This is how should look the action: exercise_12_action