-
Notifications
You must be signed in to change notification settings - Fork 0
Methods
Efra Espada edited this page Aug 1, 2018
·
10 revisions
Client methods can be used in multiple processes/clusters.
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.
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))
});
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")
});
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]))
}
});
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]))
}
}
);
{
"age": 0, masks the age as integer
"device": {}, masks everything inside object
"members": { masks only the rol field of subitems
"*": {
"rol": ""
}
}
}
Copyright 2018 Efraín Espada
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.