Data Types

Database data types.

The Appery.io Database has the following types.

Date

The Date type value is a string which contains a UTC timestamp stored in ISO 8601 format with millisecond precision: YYYY-MM-DDThh:mm:ss.mmm.

Array

An array value is a list of primitive values, such as: string, number or boolean.
cURL:

curl -X POST
   -H "X-Appery-Database-Id: 544a5cdfe4b03d005b6233b9"
   -H "Content-Type: application/json"
   -d '{"marks": [6,7,3]}'
   https://api.appery.io/rest/1/db/collections/students/

Example above will create a new entry in the students collection with marks field type of array.

Pointer

As MongoDB is not a relational database, it can’t perform SQL join operations. Instead, there are pointer types that are used as references to another object. It contains the collection name and _id of the referred-to value. Let’s say that the students collection contains the owner column. That column contains the user ID from the Users collection.

The result of the GET request will look like:

{
        "_id":"5278cb0ae4b01085e4b7945f",
        "_createdAt":"2013-11-05 10:40:10.400",
        "_updatedAt":"2015-06-19 13:36:14.844",
        "marks":[
            7.0,
            6.0,
            5.0
        ],
        "studentId":30.0,
        "studentName":"Sasha",
        "owner":{
            "collName":"_users",
            "_id":"55841aafe4b04bd7168221e2"
        }
    }

To read multiple children for a parent, use the following where parameter, where columnName is the name of the column with type=pointer and _id is the referenced object of the todo database:

{"columnName": {"$inQuery" : { "_id": "54da2471e4b0e533414b6115"}}}

The pointer value can be set using a POST command and by passing two parameters – collName and _id of referenced object:

cURL:

curl -X POST
   -H "X-Appery-Database-Id: 542416a1e4b0b7fdcc764eb0"
   -H "Content-Type: application/json"
   -d '{"owner": {"collName":"_users", "_id":"5540ed6ae4b020ea2fabaf44"}}'
   https://api.appery.io/rest/1/db/collections/students/

Example above will create a new entry in the students collection with owner field type of pointer.

To retrieve the referenced object value (not a pointer value) use the include parameter.

Example

This example shows how to use Server Code script and Pointer data type to setup user registration – Learn How to Create a User Registration Form with the Appery.io Database and Server Code .

Object

Object type is a general representation of a JSON object, which can have any structure. When an object with object type is given, the column value is specified as a JSON object in { } brackets. Object type also supports querying.

📘

Note

Read more about querying.

GeoPoint

The Geopoint type is used to define a geographic location with longitude and latitude, and presented as an array of two values.
Please mind that longitude goes first!

We are using 2dsphere indexes for Geopoint: https://docs.mongodb.com/v3.2/geospatial-queries/#legacy-coordinate-pairs

cURL:

curl -X POST
   -H "X-Appery-Database-Id: 526fdbd8e4b07c3286b537f1" 
   -H "Content-Type: application/json" 
   -d '{"location": [16.373, 48.208], "name": "Vienna"}' 
   https://api.appery.io/rest/1/db/collections/cities/

File

File type can be used to store any sort of file. While clicking on the cell with the File type, the Media Manager opens. By clicking “Upload file,” you can choose any file with a non-empty body and size up to 20MB. You can also insert the same file in other rows.

To remove a file from a certain row, click on a cell where it is located and then choose “Reset” in Media Manager.

To remove files from the Media Manager, choose the needed file and click “Delete file.” This operation cannot be undone.

All uploaded files are added to the predefined Files collection. This also works conversely: if the file was added to the predefined Files collection, it will also be available in Media Manager.

Media Manager only contains files related to a database where they have been added.

File type object must contain originalFileName and fileName fields.