Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

renamed sf.js => salesforce.js

  • Loading branch information...
commit 53232d4e0944c8dd38a307186e0a83b1fc9516ca 1 parent d769663
@stomita authored
View
1  index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/salesforce');
View
46 lib/sf.js → lib/salesforce.js
@@ -326,21 +326,42 @@ util.inherits(Query, events.EventEmitter);
/**
*
*/
-Query.prototype.maxFetch = 10000;
+Query.prototype._maxFetch = 10000;
+Query.prototype.maxFetch = function(maxFetch) {
+ this._maxFetch = maxFetch;
+ return this;
+};
+
+/**
+ *
+ */
+Query.prototype._autoFetch = false;
+Query.prototype.autoFetch = function(autoFetch) {
+ this._autoFetch = autoFetch;
+ return this;
+};
+
/**
*
*/
Query.prototype.run =
Query.prototype.exec =
-Query.prototype.execute = function(callback) {
+Query.prototype.execute = function(options, callback) {
+ options = options || {};
+ if (typeof options === "function") {
+ callback = options;
+ options = {};
+ }
if (typeof callback === "function") {
this.once('response', function(res) { callback(null, res); });
}
var self = this;
- if (!self._locator) {
- self.totalFetched = 0;
- }
+ var autoFetch = options.autoFetch || self.autoFetch;
+ var maxFetch = options.maxFetch || self._maxFetch;
+
+ if (!self._locator) { self.totalFetched = 0; }
+
var url = self._locator ?
self._conn.urls.rest.query + "/" + self._locator :
self._conn.urls.rest.query + "?q=" + encodeURIComponent(self._soql);
@@ -352,19 +373,20 @@ Query.prototype.execute = function(callback) {
self.emit("error", err);
return;
}
- self.emit("response", data);
+ self.emit("response", data, self);
self.totalSize = data.totalSize;
_.forEach(data.records, function(record, i) {
- if (!self.stopQuery) {
- self.emit('record', record, i, self.totalFetched++);
- self.stopQuery = self.totalFetched >= self.maxFetch;
+ if (!self._stop) {
+ self.emit('record', record, i, self.totalFetched++, self);
+ self._stop = self.totalFetched >= maxFetch;
}
});
- if (!data.done && self.autoFetch && !self.stopQuery) {
+ if (!data.done && autoFetch && !self._stop) {
self._locator = data.nextRecordsUrl.split('/').pop();
- self.execute();
+ self.execute(options, callback);
} else {
- self.emit('end', self.totalFetched);
+ self._stop = true;
+ self.emit('end', self);
}
});
};
View
3  test/config/sf.js.example → test/config/salesforce.js.example
@@ -1,8 +1,9 @@
/**
- * copy and save this as "sf.js", by filling proper information;
+ * copy and save this as "salesforce.js", by filling proper information;
*/
module.exports = {
loginServerUrl : "https://login.salesforce.com",
username : "usernamen@example.org",
password : "your password is here"
+// , bigTable : "BigTable__c"
};
View
9 test/sf.test.js → test/salesforce.test.js
@@ -1,7 +1,7 @@
var vows = require('vows')
, assert = require('assert')
- , sf = require('../lib/sf')
- , config = require('./config/sf')
+ , sf = require('../lib/salesforce')
+ , config = require('./config/salesforce')
;
var conn = new sf.Connection({});
@@ -35,14 +35,13 @@ vows.describe("salesforce").addBatch({
query.on('record', function(record, i, cnt){
records.push(record);
});
- query.on('end', function(fetched) {
+ query.on('end', function() {
self.callback(null, { query : query, records : records });
});
query.on('error', function(err) {
self.callback(err);
});
- query.autoFetch = true;
- query.run();
+ query.run({ autoFetch : true });
},
"should scan all tables" : function(result) {
Please sign in to comment.
Something went wrong with that request. Please try again.