(callback)
| 828 | }; |
| 829 | |
| 830 | find(callback) { //find the document(s) matching the given query |
| 831 | if (!CB.appId) { |
| 832 | throw "CB.appId is null."; |
| 833 | } |
| 834 | if (!this.tableName) { |
| 835 | throw "TableName is null."; |
| 836 | } |
| 837 | var def; |
| 838 | if (!callback) { |
| 839 | def = new CB.Promise(); |
| 840 | } |
| 841 | |
| 842 | var thisObj = this; |
| 843 | |
| 844 | var params = JSON.stringify({ |
| 845 | query: thisObj.query, |
| 846 | select: thisObj.select, |
| 847 | sort: thisObj.sort, |
| 848 | limit: thisObj.limit, |
| 849 | skip: thisObj.skip, |
| 850 | key: CB.appKey |
| 851 | }); |
| 852 | |
| 853 | var url = CB.apiUrl + "/data/" + CB.appId + "/" + thisObj.tableName + '/find'; |
| 854 | |
| 855 | CB._request('POST', url, params).then(function(response) { |
| 856 | var object = CB.fromJSON(JSON.parse(response)); |
| 857 | if (callback) { |
| 858 | callback.success(object); |
| 859 | } else { |
| 860 | def.resolve(object); |
| 861 | } |
| 862 | }, function(err) { |
| 863 | if (callback) { |
| 864 | callback.error(err); |
| 865 | } else { |
| 866 | def.reject(err); |
| 867 | } |
| 868 | }); |
| 869 | |
| 870 | if (!callback) { |
| 871 | return def.promise; |
| 872 | } |
| 873 | }; |
| 874 | |
| 875 | findFromLocalStore(callback) { |
| 876 |
no outgoing calls
no test coverage detected