Learn How to Perform Basic Database Operations: Create, Read, Update, and Delete

The Appery.io Backend Services consists of the following components:

  • Database – for storing any app data.
  • Server Code – for writing server-side app logic using JavaScript.
  • API Express – integrating with external systems and APIs.
  • Push Notifications – sending push messages to devices.
  • Web Hosting – publishing and hosting mobile web apps.

In this post, we will show you how a Server Code script integrates with the Database.

One of the most common questions we get is how to work with the database, how to create, edit and delete data. This makes sense as virtually any mobile app needs to store data in a database and perform these basic operations. To access the database, we are going to use Server Code script. Server Code allows writing app logic using JavaScript which will be executed on the server. For example, a script can access the database, send a Push Notification message, sort data and invoke an external REST API. We will start with the most basic operation: how to read data from the database.

The database collection used in this post looks like this:


Database collection.

This can be data collected from a form inside an app – a form that collects information about the user.

Reading Data

Server Code script has out-of-the-box API to access the database to perform all the basic operations. The following script reads all objects from the above collection.

var dbApiKey = "fe7c124b-f7c5-4764-9274-173b56a97102";
var result = Collection.query(dbApiKey, "Data");
Apperyio.response.success(result, "application/json");

One line 2, the script retrieves all the data.

One line 3, the script response is set. A Server Code script is invoked as a REST API. The code on this line defines the API response.

A script can be quickly tested from the Run tab where you can see the JSON data:



Script testing.


Reading data from a database collection is fast and simple. Next, we are going to save data into the database.

Continue reading

How to Build and Test an Ionic SMS App

This video shows how to build and test an Ionic SMS app using Nexmo API. The video tutorial first shows how to create a backend to invoke Nexmo API. Then the Ionic app is created which uses the backend. The app is then tested in the browser and on the device using the Appery.io Tester app. The video also shows how to build a binary file for Android and iOS.

Looking for more videos to help build mobile apps? Check out the Appery.io YouTube channel.

Video Tutorial: How to Build a REST API for a Custom SQL Query

This video shows how to use the SQL and Script components to build a Login service. The SQL component runs a custom SQL query to check if a user exists in a database. The Script component adds custom logic to check what the SQL component returned and defines the response (user found or user not found).

Looking for more videos on enterprise integration? Watch the API Express playlist.

Video: How to Build an Ionic App with an RSS Feed

This short video shows how to build an Ionic app that connects to an RSS feed. You can click on a link and navigate to the article. RSS feed used in this tutorial: http://feeds.gawker.com/lifehacker/full.

There are many more videos on the Appery.io YouTube channel to help you build mobile apps fast.

Video: Learn How to Build a Mobile App with External REST API

This short video shows how to build a complete app with an external REST API. This video covers:

  • Using API Express to connect to an external REST API. https://randomuser.me/ is used for the API.
  • Importing API Express service into the app (App Builder).
  • Designing the app UI (1 page).
  • Binding and using the service from the page.
  • Testing the app.

Looking for more videos? Visit the Appery.io YouTube channel for many more short videos.

Learn How to Connect Your App to an API Backend

This short video shows how to import backend services APIs into your app. Appery.io services consist of a cloud database, Server Code for custom app logic, and API Express for enterprise integration and service orchestration.

Our YouTube channel has many more short videos where you can learn how to build apps fast with Appery.io.

Moving App Logic to the Server: How to Save and Query an Appery.io Database from Server Code Script

The Appery.io Database provides storage for your mobile app data. You can store data such as users, orders, purchases, products or anything else. The Appery.io Database is a cloud NoSQL database and provides a very simple and elegant REST API to work with the database.

One of the most common cases for an enterprise mobile app is to create/save a new item/record and then redisplay the list in the app with the newly created item.

Accessing the database directly from the client is fine but requires two requests to the database.

  1. A request to save the new item/record into the database.
  2. Once the 1st request completes, on its success, a request to get the updated list to display in the app.

A better approach is to do both the create and list in a single request from the app. This is very simple to do from Appery.io Server Code script. The following script shows how to create a new record and then get the updated list:

var dbId = "cdaec951....d8";
var collectionName = "People"

var newName = request.get("name");
var newTitle = request.get("title");

// Save new object into the collection
Collection.createObject(dbId, collectionName, {
   "name": newName,
   "title": newTitle

// Retrieve updated data from the collection
var result = Collection.query(dbId, collectionName);
// Return the updated list (including the new object)
Apperyio.response.success(result, "application/json");

In this simple script you first create a new Person object (line 8) and then do another query to get the updated list of people (line 14). The script response returns the updated list of people. This script automatically has a REST API which is the invoked from the app.

What’s most important, there is only a single request from the app to the Server Code script. A single request is usually better than two requests. Also, you can add additional logic to the script without impacting the app. For example, you can send an email when a new person is added. Or, you can send  Push Notification when a new person is added. All this can be done without impacting the app. That’s nice.

If you want to learn more about Server Code, check out our YouTube channel Server Code playlist.

Tutorial: Building a Hello World App with Ionic

In this tutorial you are going to build a Hello World app with Ionic in Appery.io. This is how the app is going to look:

Screen Shot 2016-05-27 at 5.04.15 PM

Appery.io App Builder for Ionic.

You should finish this tutorial in about 10 minutes.

Continue reading

Moving App Logic to the Server: How to Query the Database From Appery.io Server Code Script

An Appery.io developer posted a question on the Appery.io Facebook page on how to write a Server Code script to query two different collections in the database. This post will show you how to do that.

In general, querying two database collections is better to do on the server-side than from the client. Doing it on the server is a lot faster and provides you with the option to update the search without impacting the client. Plus, you can add any logic when needed. Doing it from the client would require two REST API calls to the database.

Let’s jump into the example.

First, there are two collections in the Appery.io Database. They look like this:

ProductName collection:

Screen Shot 2016-05-24 at 4.42.32 PM

ProductName collection.

This collection is simple. It has a name and a code.

This is the ProductData collection:

Screen Shot 2016-05-24 at 4.44.33 PM.png

ProductData collection.

The code in this collection links the product name to the actual product (Android or iOS device).

The input to the script is the product type: Android or iOS. Based on the input, you lookup the code for the product (a or i) and then run a second query to find all iOS or Android phones in the ProductData collection. Here is the script.

var product = request.get("type");
var dbId = "367e9e77......";
var params = {};
var result = [];

// Search for object with the provided 'type' (iOS or Android)
params.criteria = {
  "name": {
    "$eq": product
result = Collection.query(dbId, "ProductName", params);

// Find all objects with code 'i' or 'a'
params.criteria = {
  "code": {
    "$eq": result[0].code // Either 'i' or 'a'
// Run the query
result = Collection.query(dbId, "ProductData", params);
// Script response (API response)
Apperyio.response.success(result, "application/json");

This script first searches the ProductName collection to find the id for iOS or Android devices. Then it searches the ProductData collection to find the actual devices.

Moving this logic to the server is a good idea as you query two collections (or even more) with a single request from the client.

If you want to learn more about Server Code, check out our YouTube channel Server Code playlist.

Can I Build [insert type] App With Appery.io?

“Can I build [insert type] app in Appery.io?” is probably one of the most common questions that we get. The answer is almost always yes, but I want to provide you with a more detailed answer.

Appery.io provides tooling to allow you to build and run hybrid mobile apps. You can build virtually any kind of app supported by the underlaying technology stack: HTML, JavaScript, CSS and Cordova (for native device access), plus REST APIs. The platform provides tools and a runtime to make it simpler and easier to build your app.

  • App Builder – for building the app (client).
    • Apache Cordova is installed in every app and gives you access to device APIs such as the camera.
  • Cloud Build – for packing the app for iOS or Android.
  • Backend Services
    • Database – cloud database for storing any app data.
    • Push Notifications – for sending targeted Push Notification messages.
    • Server Code – for coding any server-side logic using JavaScript.
    • API Express – for integrating with external/enterprise systems.
  • Appery.io Tester app – for fast testing of iOS and Android apps built in Appery.io without installing them directly on the device.

The platform provides you with the tooling and runtime services, which you would need to build a successful app. Having said this, the actual app logic still has to be coded or developed. For example, let’s say you want to send a Push Notification and email when a new users registers, and also record the activity into an external relational database. You can easily build this flow/logic in Appery.io.

  • The app UI (pages, navigation) is built in the App Builder.
  • The Database has built-in user management capability. This means you can register a new user and do a login/logout.
  • When a new user is created, you can write a Server Code script to send a Push Notification message and use email API (such asSendGrid) to send an email notifying people about this event.
  • Using API Express you can connect and expose a relational database via REST API. When a new user registers, you can invoke the API and record this event (registration) into an external relational database.
  • Using the Appery.io Tester app you can quickly test the app on the device (without actually installing it) and test any native APIs.
  • After the testing, you can build and package the app for iOS or Android with Cloud Build.

In general, Appery.io is a perfect fit for building and running business and enterprise mobile apps. Another way to look at our platform is that it is ideal for creating content or data-drive apps. You can also find the term form-based used sometimes. We don’t recommend to build apps that are heavy on graphics. This is not a Appery.io limitation, but a limitation of hybrid apps in general.

We hope this blog post clarifies what kind of apps you can build with Appery.io. We many videos on our YouTube channel to help you learn how to build apps to check out the channel.

Here is another blog post that talks about this topic: What Kind of Apps Can You Build with Appery.io?.