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.

How to Simplify Enterprise Integration for Mobile Apps with Appery.io API Express

This is a 3rd webinar in our 2016 webinar series that shows how to create a custom REST API that’s composed of external REST API, SOAP service and custom logic.

You will learn:

  • How to connect to an external REST API
  • How to apply custom logic to REST API response
  • How to connect to an external SOAP service
  • How to pass custom response to SOAP service
  • How to create custom REST API response
  • How to test the final REST API

Looking for more videos on how to build mobile app fast? Check out our YouTube channel.

How To Build a Translator Mobile App with Local Storage

This video shows how to build a Translator with mobile app with Translated API and local storage:

API used in this app: http://mymemory.translated.net/doc/spec.php

Video: Build a complete HTML5/PhoneGap mobile app with Appery.io Cloud Development Platform

This video was created as part of AT&T Bootstrap Week. The video shows how to build an HR (Human Resources) mobile app. The tutorial covers:

  • Building mobile app UI with jQuery Mobile using the visual builder
  • Connecting to cloud database
  • Displaying employee list
  • Adding new employe
  • Using Google Maps component and Geolocation to to show employee location
  • Using Google Geocoding API to resolve location  to address
  • Packaging the app for Android

Help Us Win With Your Vote Now – We Made Finalist for the 2013 MobITs Award

Great News!  A panel that included industry influencers such as Ovum, Strategy Analytics, Frost and Sullivan and IHS selected Appery.io as a finalist to win the 2013 MobITs award in the category of “Applications and Platforms for Enterprise Extensions to Mobile.”  This is quite exciting for us, specially after also recently receiving the 2013 Mobile Merits Award for Best Enterprise Product or Service.  This has only been possible because of the great support we get from our community, so thank you!

Help us WIN with your Vote Now!

The winners will be selected by a popular vote on the internet.  Please vote for our entry NOW.  To vote, simply click on the image below:

MobITS_Banner_Vote_300x100 (1)

and then click on the “Sign Up/Sign In to vote” link on the upper right of that page.   Please note the deadline!

The winners will be announced at the MobiCON 2013 on October 17, in San Jose, CA where in fact, we will be speaking at one of the thought leadership sessions.

Thank you for your support!

Disrupting Mobile Development: Cloud Tools [Slides]

Slides from Progress User Group (PUG) Challenge Americas 2013 in June 9-12, 2013 in Westford, MA

Appery.io Team At TechCrunch Disrupt Hackathon — Win Awesome Prizes!

 

ny-disrupt-2013-logo appery_io (1)

 

This weekend (April 27-28) Appery.io team is going to be at the TechCrunch Distrupt Hackathon in New York City. We are going to be offering great prizes if you build your app using the Appery.io platform.

  • 1st place best app: $3,500
  • 2nd place best app: $,1000
  • 3rd place best app: $500

But, you can win even more! There are many other sponsors, in particular API sponsors that offer prizes if you build an app using their APIs. To help you win even more prizes, we have built plug-ins for various API sponsoring the hackathon:

  • AT&T In-App Messaging and Location API (up to $7,000 in prizes)
  • CrunchBase API (tickets to TC Disrupt conference in Berlin)
  • Pearson API ($500 worth of Amazon gift cards)
  • Twilio API

By building your app in Appery.io with some of the APIs that also offer prizes, you increase your chances of winning! Appery.io team will be there during the hackathon to answer any questions you might have.

We have created a special hackathon page where you can sign up for a free Pro plan and watch a recording of  a special webinar, prepared just for the hack.

Good luck and hope to see you there!

Learn How to Build Mobile Apps Using Cloud Services at Apps World, London, Nov 29-30

Apps World

Next week I will be London at Apps World conference showing how to build mobile apps in the cloud with Tiggr. Exadel is going to have a booth at the conference and also a session in the free Developer Zone area. Stop by and learn how to build a real mobile in under 5 minutes!

Learn how to Build Mobile Apps Using Cloud Services
When: Nov 30, 10:20

In this cool session you will learn how to build HTML5 and native apps using Tiggr. Tiggr is a cloud-based mobile apps builder. A real mobile app will be built during the session, which attendees will be able to run and test apps on their own devices

Learn How To Build Mobile Apps Using Cloud Services at appsworld, New York

appsworld New York

If you are at appsworld conference in New York, Nov 1-2, you will be able to see the most awesome way to build mobile apps using cloud-based mobile apps builder, Tiggr.

Learn How To Build Mobile Apps Using Cloud Services
November 1, at 13:00
In this cool session you will learn how to build HTML5 and native apps
using Tiggr. Tiggr is a cloud-based mobile apps builder. A real mobile
app will be built during the session, which attendees will be able to
run and test on their own devices.

Tiggr (Exadel) is also exhibiting so stop by our table, say hello and see how to build a mobile app in about 5 minutes.

Building Mobile Apps With jQuery For Any Device In The Cloud [Conference Tutorial]


OSCON 2011

On Wednesday July 27 during OSCON conference, I will be doing a tutorial on building mobile apps with jQuery in the cloud using Tiggr Mobile Apps Builder. If you are attending the conference, there is still time to sign up for this tutorial.