Datastores are AirData's conceptual way of grouping tables and data. A datastore contains information about AirData App Objects and all the data or rows stored in the AirData. Datastores are particularly useful for setting up different environments like Production and Staging. This document will serve as an overview of datastores and how they can be used. It will contain the following topics:
Datastore and Profiles
Datastores are currently associated with profiles. While this isn't a strict 1 to 1 relationship, at any given time, only one datastore can be active on one profile. While it is theoretically possible to use a datastore in more than one profile, this can lead to developer confusion and is advised against. Datastores are tied to Organizations, so while other apps datastores are available in the datastore dropdown, it is advised against using the same datastore in multiple different apps. App Objects are tied to the app, so even though two apps use an App Object with the same name, the same data is not directly accessible to both apps.
Understanding Profiles covers the basics of profiles. Profiles contain the configuration information for a published instance of an application. You can modify the profile information in Configuration Builder.
The profile is selected at the top of the Configuration Builder. To modify the data source used with a Profile. Select the profile from the dropdown at the top of Configuration Builder:
With the desired profile selected, select the Data Store and save. This will bind the datastore to the profile. When an app is deployed or previewed, it will use the associated data store.
The Datastore button in Data Builder
In Data Builder, there is a button at the top of the tree titled Datastore:
Clicking this button presents the datastore dialog box. Selecting the button at the right of a datastore presents datastore action options.
This dialog lists all of the Datastores available to your organization.
- Clone - duplicate the existing data store into a new datastore.
- Backup - create a new version of the existing datastore for backup
- Delete - remove the datastore from the organization.
To select a backup or cloned datastore, I got back to Configuration Builder to select the datastore in the dropdown with the current profile selected.
App Objects binding to Data Stores
AirData App Objects are objects created within Data Builder that bundle data fields together. Once defined, AirData App Objects can be used throughout an app wherever data types are used. When an App Object is defined, the definition is stored in the Datastore.
When an AirData App Object is used to store data, the data is stored in the table. This makes Datastores an ideal place for storing configuration information for each environment.
To demonstrate this, let's create two different sets of towing services for our app. One set will be mock data used in the staging environment for testing, and one set will be the data shown to the user. This approach's benefit is that there is no contact to production towing services while testing in staging.
Go to Configuration Builder. Click the + button in the top right to two more profiles, "Staging" and "Production." Next, go to Data Builder. Create a new AirData App Object by clicking the + icon at the top of the tree. Name the app object "Towing Provider" and give it the properties name (Text) and phone (Phone). Enter two to three records of real towing companies. This will serve as the production data.
To create the new datastore, click the Datastore button. Find the Datastore that is currently labeled with "Primary." Select the "..." button to the right. Select the Clone option. Enter "Towing Staging Datastore" into the Datastore Name box. Click Save. While this creates the new Datastore, go to Configuration Builder to adjust the profile's data store.
In Configuration Builder, select the staging profile from the Profile selector dropdown. In the Datastore section, select the new "Towing Staging Datastore" you created. Click Save. Go back to Data Builder and configure the Towing Provider in staging with some test options. Switching between profiles will switch the data available in the Towing Provider database.
Exporting and Importing Data
Inside Data Builder, it is possible to export and import data into app Objects. This data will be stored with the Datastore. Exporting data from an AirData App Object is as simple as selecting the Object in Data Builder. There is an "Export table as CSV" button in the inspector on the right.
To import data into an AirData, format the data in a spreadsheet app in the columns match each of the AirData App Object fields. Copy the data from the spreadsheet and paste it in a new row on the destination table.