-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathsoql.js
46 lines (39 loc) · 1.36 KB
/
soql.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module.exports = function(RED) {
var nforce = require('nforce');
function Query(config) {
RED.nodes.createNode(this,config);
this.connection = RED.nodes.getNode(config.connection);
var node = this;
this.on('input', function(msg) {
// show initial status of progress
node.status({fill:"green",shape:"ring",text:"connecting...."});
// use msg query if node's query is blank
if (msg.hasOwnProperty("query") && config.query === '') {
config.query = msg.query;
}
// create connection object
var org = nforce.createConnection({
clientId: this.connection.consumerKey,
clientSecret: this.connection.consumerSecret,
redirectUri: this.connection.callbackUrl,
environment: this.connection.environment,
mode: 'single'
});
// auth and run query
org.authenticate({ username: this.connection.username, password: this.connection.password }).then(function(){
return org.query({ query: config.query })
}).then(function(results) {
msg.payload = {
size: results.totalSize,
records: results.records
}
node.send(msg);
node.status({});
}).error(function(err) {
node.status({fill:"red",shape:"dot",text:"Error!"});
node.error(err);
});
});
}
RED.nodes.registerType("soql",Query);
}