Home > Uncategorized > #NoSQL Implement persistent key/value storage in #JavaScript

#NoSQL Implement persistent key/value storage in #JavaScript

nosql

nosql.apixml.net

Implement persistent Key/Value storage using client side java script only

Installation

    http://nosql.apixml.net/nosql.js

Save data

    var id = nosql.guid();
    nosql.put(id,"hello world").then(function (data) {
           // This stores "Hello world"
    });

Load data

    nosql.get(id).then(function(data){
            alert(data);
    });

Each key in the store must be a GUID (i.e. 9ED4B528-7F5F-3074-BBBF-947C6133ED13), this is to prevent overlaps between your keys and other user’s keys. Data can be any string, typically this would be json, but you can store any UTF8 string (not binary data).


This is backed by a REST API, which you make a GET, POST, or DELETE request to http://nosql.apixml.net/%5BGUID%5D to retrieve, update/insert and delete data respectively.

Advertisements
Categories: Uncategorized
  1. September 20, 2017 at 2:05 pm

    Here’s a C# client code, for getting and storing any object remotely.

    private static readonly WebClient Wc = new WebClient();
    private static readonly JavaScriptSerializer JsSerializer = new JavaScriptSerializer();

    public static void Put(T o, Guid id)
    {
    var strJson = JsSerializer.Serialize(o);
    Wc.UploadString(“http://nosql.apixml.net/” + id, strJson);
    }

    public static T Get(Guid id)
    {
    var strJson = Wc.DownloadString(“http://nosql.apixml.net/” + id);
    return JsSerializer.Deserialize(strJson);
    }

  2. October 4, 2017 at 2:40 pm

    A handy bit of code to create deterministic GUIDs (i.e. guids that are consistent, given a provided string) is here

    public static Guid ToGuid(string src)
    {
    byte[] stringbytes = Encoding.UTF8.GetBytes(src);
    byte[] hashedBytes = new System.Security.Cryptography
    .SHA1CryptoServiceProvider()
    .ComputeHash(stringbytes);
    Array.Resize(ref hashedBytes, 16);
    return new Guid(hashedBytes);
    }

    This allows you store based on a key/value as string/object rather than guid/object

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: