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))); } });
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Pawanpreet Singh
Pawanpreet Singh is a technical project manager with experience in Web and Mobile apps development . Pawanpreet loves playing games on PS4 and going out with friends in free time.