Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Azure data operations

  • Loading branch information...
commit e30974aa907eb494f0d1b92b5c75a01e48ddea0e 1 parent ecfdc50
@Redth authored
Showing with 110 additions and 4 deletions.
  1. +110 −4 Azure-Table-Scripts.js
View
114 Azure-Table-Scripts.js
@@ -1,7 +1,13 @@
/*
+* AZURE MOBILE SERVICES - Data Table Scripts
+*
+* From the dashboard of your mobile service, go to the DATA tab
+* Create each of the following tables, open each table and go to
+* the SCRIPT tab of each table.
*
-*
-*
+* In each table's script section, paste and save the following
+* scripts which correspond to each table operation
+*
*/
@@ -10,12 +16,112 @@
//-----------------
//READ
-
+// NO CHANGE from Default
//INSERT
+function insert(item, user, request) {
+ item.UserId = user.userId;
+ request.execute();
+}
+
+//UPDATE
+function update(item, user, request) {
+ item.UserId = user.userId;
+ request.execute();
+}
+
+//DELETE
+function del(id, user, request) {
+
+ //Need to delete any associated Entries to the list being deleted
+ var entryTable = tables.getTable('Entry');
+
+ entryTable.where({ListId: id}).read({
+ success: function(results) {
+ if (results.length > 0) {
+ for (var i = 0; i < results.length; i++) {
+ entryTable.del(results[i].id);
+ }
+ }
+
+ //Finally, allow the delete of the actual list
+ request.execute();
+ }
+ });
+}
+
+
+
+//-----------------
+// TABLE: Entry
+//-----------------
+
+//READ
+// NO CHANGE from Default
+//INSERT
+function insert(item, user, request) {
+ item.UserId = user.userId;
+ request.execute();
+}
//UPDATE
+function update(item, user, request) {
+ item.UserId = user.userId;
+ request.execute();
+}
+
+//DELETE
+function del(id, user, request) {
+
+ var entryTable = tables.getTable('Entry');
+
+ entryTable.where({Id: id}).read({
+ success: function(results) {
+ if (results.length > 0) {
+ if (results[0].imageGuid) {
+ var imageGuid = results[0].imageGuid;
+ deleteEntryImage(id, user, request, imageGuid);
+ }
+ }
+ }
+ });
+
+ request.execute();
+}
+
+//Deletes a leftover EntryImage for the specified ImageGuid
+function deleteEntryImage(id, user, request, imageGuid) {
+ var entryImageTable = tables.getTable('EntryImage');
+
+ entryImageTable.where({ImageGuid: imageGuid}).read({
+ success: function(results) {
+ if (results.length > 0)
+ entryImageTable.del(results[0].id);
+ }
+ });
+}
+
+
+//--------------------
+// TABLE: EntryImage
+//--------------------
+
+//READ
+// NO CHANGE from Default
+
+//INSERT
+function insert(item, user, request) {
+ item.UserId = user.userId;
+ request.execute();
+}
+
+//UPDATE
+function update(item, user, request) {
+ item.UserId = user.userId;
+ request.execute();
+}
-//DELETE
+//DELETE
+// NO CHANGE from Default
Please sign in to comment.
Something went wrong with that request. Please try again.