0.0.18 • Published 9 years ago

gelato v0.0.18

Weekly downloads
39
License
-
Repository
-
Last release
9 years ago

Mobile Cloud Services JavaScript SDK for IBM Mobile Data for Bluemix

This package contains the required native components to interact with the IBM Mobile Cloud Services for Bluemix. You can use the JavaScript SDK to build server-side applications Node.js

When you use Bluemix to create a Mobile Cloud application, BlueMix provisions multiple services under a single application context. Your mobile application is given access to the following mobile services: Mobile Data.

Get the SDK with NPM (Node.js)

NPM is included in current Node.js distributions. To install Node.js, go to Download Node.js.

Use the following command to install the ibmdata package:

npm install gelato

##Get started

//
// edit config/default.json and enter your app info
//
// {
//     "gelato" : {
//         "agent" : <agent URL>
//         "agentPort" : <agent port>,
//         "appId" : <appid>,
//         "appSecret" : <app secret>,
//         "appKey" : <app key>
//     }
// }
//

// initialize sdk
var gelato = require('gelato')

// issue a query
gelato.query( query, function(err, docs) {
    ...
})

// find all instances of a given type
gelato.ofType(className, function(err, docs) {
    ...
})

// find the object with the given id
gelato.forObjectId(id, function(err, obj) {
    ...
})

// create an object
gelato.create(className, { "name" : "bob", age : 30 }, function(err,obj) {
    ...
})

// delete by ID
gelato.deleteById(id, function(err, res) {
   ...
})

// find all class names
gelato.classNames(function(err, names) {
   ...
})

// save an object
gelato.save(obj, function(err,res) {
   ...
})

// The low-level query API
//     limit might be lowered by implementation
gelato.query({ limit : 10, predicate : { x : 10 }}, function(err,res) {
    if (err) throw ...
    var bookmark = res.bookmark
    var objects = res.objects
    var n = objects.length
    ...
});

// The predicate API, you can't specify limit, bookmark, ...
gelato.perdicate({ x : 10}, function(err, res) {
   ...
});

// The batch API, we give you arrays of objects
//       limit is per batch
//       we'll keep feeding you objects until either:
//             - no more objects or
//             - you don't call next
gelato.batch({ limit : 10}, function(err, array, next) {
    if (err) throw ...

    if (array == null) {
        // no more objects
    } else {
        // work with array of objects
        if (needMore) {
            next()
        } else {
            // don't call next
        }
    }
})
        
// The stream API, we give you one object at a time
//       limit is a hint for how many to bring from server per request
//       we'll keep feeding you objects until either:
//             - no more objects or
//             - you don't call next
gelato.batch({ limit : 10}, function(err, obj, next) {
    if (err) throw ...

    if (array == null) {
        // no more objects
    } else {
        // work with array of objects
        if (needMore) {
            next()
        } else {
            // don't call next
        }
    }
})
        
// convenience predicate generator
var predicate = gelato.eq('x',10).eq('.className',"Person").gen();
var predicate = gelato.eq('x',10).or(gelato.eq('y',100)).gen();

// you can also generate complete queries
var query = gelato.eq('x',10).gt('y',200).limit(10).bookmark('ERFVs').gen();

// you can also issue a query directly
gelato.eq('x',10).eq('z','abc').stream(function(err,obj,next) {
    ....
})

// generic RPC
gelato.rpc('service','method',attributes,function(err, reply) {
    ...
})

##Learn More

Licensed Materials - Property of IBM (C) Copyright IBM Corp. 2013, 2014. All Rights Reserved. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

Terms of Use | Notices

0.0.18

9 years ago

0.0.17

10 years ago

0.0.16

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago