Skip to content

Methods

Efra Espada edited this page Aug 1, 2018 · 10 revisions

Client methods can be used in multiple processes/clusters.

server

Starts Turbine server on a different process. This should be called first when your API is starting.

turbine.server();
starting ..
Indexed 22793.
started on 4005 (15.749 secs)
0 op/sec
{
    "users": {
        "userA": {
            "name": "John",
            "age": 1
        }
    }
}

Once Turbine is started, you can use client methods.

get

Client method that looks for an object on the given path.

turbine.get("databaseA", "/users/userA").then(function(user) {
   /*
        {
            "name": "John",
            "age": 1
        }
   */
    console.log(JSON.stringify(user))
});

post

Client method that updates or removes an object on the given path passing another object or null.

let newUser = {
    name: "Matt J.",
    age: 79
}
turbine.post("databaseA", "/users/userB", newUser).then(function() {
   /*
        {
            "name": "Matt J.",
            "age": 79
        }
   */
    console.log("stored")
});

query

Client method that looks for an object on the given path for the conditions passed.

turbine.query("databaseA", "/users/*", { name: "Matt J." }).then(function(users) {
    for (let user in users) {
        /*
            [
                {
                    "name": "Matt J."
                    "age": 79
                }
            ]
        */
        console.log(JSON.stringify(users[user]))
    }
});

Masks

get and query methods have an additional parameter for result mutating.

turbine.query("databaseA", "/users/*", 
    {
        name: "Matt J."
    },
    {
        age: 0
    }
).then(function(users) {
        for (let user in users) {
        /*
            [
                {
                    "age": 79
                }
            ]
        */
            console.log(JSON.stringify(users[user]))
        }
    }
);

Masks

{
    "age": 0,        masks the age as integer
    "device": {},    masks everything inside object
    "members": {     masks only the rol field of subitems
        "*": {
	    "rol": ""
	}
    }
}
Clone this wiki locally