top of page
Hello Data

Hello Data

Get started with the Data API

Intermediate.png

Beginner

3K

Published:

December 18, 2022

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

In this example, we demonstrate how to perform CRUD (create, read, update, and delete) operations using the Data API.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It

Collection Data


To demonstrate the CRUD operations we created a collection named 'Greetings'. The collection holds the greeting "Hello World!" in a number of different languages. The collection has two fields with the keys `language` and `greeting`.


Page Elements


The HOME page contains:

  • A repeater for displaying data from the database collection

  • A small form with two text inputs for creating and updating collection items

  • Three buttons used to perform the read, update, and delete operations


Code


The HOME page contains code for performing the CRUD operations as well as code for implementing the UI functionality of handling button clicks, displaying retrieved items, selecting items, and the like. There is no need to look at this code to understand the CRUD operations, so we will not analyze it here.


Each of the four CRUD operations is encapsulated in a function.

  • createGreeting(): This function builds an object from the `language` and `greeting` arguments that are passed to it. We then use this object when calling the `insert` function to create a new 'Greetings' item. Note how the properties of the object we use match up with the field keys of the 'Greetings' collection,

  • readGreetings(): This function reads all the items in the 'Greetings' collection. We build a query by calling the `query()` function. We add a call to the `ascending()` function to retrieve the items sorted by language. We can also add filtering functions like `eq()`, `startsWith()`, and `contains()` to refine our query. Once the collection is built, we call the `find()` function to run the query.

  • updateGreeting(): This function builds an object from the `itemId`, `language`, and `greeting` arguments that are passed to it. The object contains an `_id` value, which indicates which item will be updated. We then use this object when calling the `update` function to update the 'Greetings' item.

  • deleteGreeting(): This function deletes a single 'Greetings' item. We call the `remove()` function with a value from one of the 'Greetings' items' `_id` fields.

APIs We Used

Non-code example.

Related Articles

Article Link

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Image placeholder.png

Add to Cart Gallery

Let customers to add products to their cart

Intermediate.png

INTERMEDIATE

Image placeholder.png

Hide and Show Elements

Hide and show elements in response to user interactions

Begginer.png

BEGGINER

Image placeholder.png

Hide and Show Elements

Hide and show elements in response to user interactions

Begginer.png

BEGGINER

Anchor 2
bottom of page