ServerStorage: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Line 30: Line 30:
|}
|}


== Example ==
== Example - BASIC ==


<pre>
<pre>
Line 56: Line 56:
   serverStorage.clear()
   serverStorage.clear()
End Function
End Function
</pre>
== Example - JavaScript ==
<pre>
function Main() {
  NameSpace.text = serverStorage.namespace;
}
Button1.onclick = function() {
  t=SysInfo(10);
  for  (i = 1; i  <= 10; i ++) {
    serverStorage.setItem("item"  +  i, i);
  }
  alert("Write 10 items into serverStorage(secs): "  +  (SysInfo(10)-t)/1000);
}
Button2.onclick = function() {
  NSB.Print(False);
  for  (i=0; i <= serverStorage.length-1; i++) {
    key = serverStorage.key(i);
    NSB.Print((key+ " " + serverStorage.getItem(key)) + "<br>");
  }
}
Button3.onclick = function() {
  serverStorage.clear();
}
</pre>
</pre>



Revision as of 16:32, 6 November 2014

serverStorage(string | variable)

Description

ServerStorage allows you to save string data on the server so it is available next time you run the program. An entry can be created by assigning to serverStorage.setItem(variableName, value), where variableName is chosen by you. Data is retrieved a similar way.

By default, the data is saved into a namespace with the same name as the app's ID. It can be set to any string, even that of another app, making it possible for apps to share data.

ServerStorage is insecure: there is currently no protection against other apps reading or changing the data.

This feature is currently experimental. It only works on apps deployed to nsbapp.com. It will not work locally or on your server at this time. Since the data is on the nsbapp.com test server, do not assume that data you save will be permanently available.

Properties and Methods

clear() Clear all entries in the current namespace.
deleteItem(key) Deletes item key.
getItem(key) Get the item which is saved under key. String.
key(n) Get the nth item in the namespace.
length The number of items in the current namespace.
namespace The group used by all serverStorage methods. Defaults to app ID.
setItem(key, value) Sets item key to value. Creates item if it does not exist.

Example - BASIC

Sub Main()
  NameSpace.text = serverStorage.namespace
End Sub

Function Button1_onclick()
  t=SysInfo(10)
  For i = 1 To 10
    serverStorage.setItem("item" & i, i)
  Next
  MsgBox "Write 10 items into serverStorage(secs): " &  (SysInfo(10)-t)/1000
End Function

Function Button2_onclick()
  NSB.Print(False)
  For i=0 To serverStorage.length-1
    key = serverStorage.key(i)
    Print key, serverStorage.getItem(key)
  Next
End Function

Function Button3_onclick()
  serverStorage.clear()
End Function

Example - JavaScript

function Main() {
  NameSpace.text = serverStorage.namespace;
}

Button1.onclick = function() {
  t=SysInfo(10);
  for   (i = 1; i  <= 10; i ++) {
    serverStorage.setItem("item"  +  i, i);
  }
  alert("Write 10 items into serverStorage(secs): "  +   (SysInfo(10)-t)/1000);
}

Button2.onclick = function() { 
  NSB.Print(False);
  for   (i=0; i <= serverStorage.length-1; i++) {
    key = serverStorage.key(i);
    NSB.Print((key+ " " + serverStorage.getItem(key)) + "<br>");
  }
}

Button3.onclick = function() {
  serverStorage.clear();
}

Output

This is Data.

Related Items

LocalStorage, SessionStorage, SQL