Custom objects in ArrowDB

Posted By : Pawanpreet Singh | 29-Jun-2015

Custom obejcts in ArrowDB are required when you want to save a thing which is not present in built in restful calls creted by Appcelerator. To overcome this situation one can create its own custom object to save that data. One can easily integrate these custom objects with the existing ArrowDB objects. Here I will give brief overview how can one use it in his/her app.

Create a custom object

 Cloud.Objects.create({
    classname: 'students',
    fields: {
        name: 'Pawanpreet',
        stream: 'medical',
        rollno: 5
    }
}, function (e) {
    if (e.success) {
        var student = e.students[0];
        alert('Success:\n' +
            'name: ' + student.name + '\n' +
            'stream: ' + student.stream + '\n' +
            'rollno: ' + student.rollno + '\n' +
            'created_at: ' + student.created_at);
    } else {
        alert('Error:\n' +
            ((e.error && e.message) || JSON.stringify(e)));
    }
});
 

 

The above code will create a new custom object named students, Custom object name will be the name of the classname which we have provided while creating a new object. Here we have added fields named - name, stream and rollno in it with its respective values.

 

Now its time to get the saved custom object for use in our app.

Getting the value of custom object

 Cloud.Objects.show({
    classname: 'students',
    ids: [ studentsIdReturnedFromServerAfterSaving ]
}, function (e) {
    if (e.success) {
        alert('Success:\n' +
            var car = e.students[0];
            alert('id: ' + students.name + '\n' +
                'rollno: ' + students.rollno + '\n' +
                'stream: ' + students.stream 
        }
    } else {
        alert('Error:\n' +
            ((e.error && e.message) || JSON.stringify(e)));
    }
});
 

About Author

Author Image
Pawanpreet Singh

Pawanpreet Singh is a mobile app lead developer with experience in Native iOS , Titanium and PhoneGap apps development . Pawanpreet loves playing games on his Nintendo Switch and going out with friends.

Request for Proposal

Name is required

Comment is required

Sending message..