MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / distinct

Method distinct

sdk/src/CloudQuery.js:777–828  ·  view source on GitHub ↗
(keys, callback)

Source from the content-addressed store, hash-verified

775 };
776
777 distinct(keys, callback) {
778
779 if (keys === 'id') {
780 keys = '_id';
781 }
782
783 if (!CB.appId) {
784 throw "CB.appId is null.";
785 }
786 if (!this.tableName) {
787 throw "TableName is null.";
788 }
789 if (Object.prototype.toString.call(keys) !== '[object Array]' && keys.length <= 0) {
790 throw "keys should be array";
791 }
792 var def;
793 if (!callback) {
794 def = new CB.Promise();
795 }
796
797 var thisObj = this;
798
799 var params = JSON.stringify({
800 onKey: keys,
801 query: thisObj.query,
802 select: thisObj.select,
803 sort: thisObj.sort,
804 limit: thisObj.limit,
805 skip: thisObj.skip,
806 key: CB.appKey
807 });
808 var url = CB.apiUrl + "/data/" + CB.appId + "/" + thisObj.tableName + '/distinct';
809
810 CB._request('POST', url, params).then(function(response) {
811 var object = CB.fromJSON(JSON.parse(response));
812 if (callback) {
813 callback.success(object);
814 } else {
815 def.resolve(object);
816 }
817 }, function(err) {
818 if (callback) {
819 callback.error(err);
820 } else {
821 def.reject(err);
822 }
823 });
824
825 if (!callback) {
826 return def.promise;
827 }
828 };
829
830 find(callback) { //find the document(s) matching the given query
831 if (!CB.appId) {

Callers 5

test.jsFile · 0.80
includeList.jsFile · 0.80
queryTest.jsFile · 0.80
distinctFunction · 0.80
distinctFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected