Skip to content

Commit 3cb8c84

Browse files
committed
Merge pull request #101 from killme2008/feature/2015.05.27
Added AV.BigQuery namespace to support bigquery
2 parents ccdc1ff + a8cc909 commit 3cb8c84

File tree

16 files changed

+578
-18
lines changed

16 files changed

+578
-18
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "leancloud-jssdk.js",
3-
"version": "0.5.4",
3+
"version": "0.5.5",
44
"homepage": "https://github.com/leancloud/javascript-sdk",
55
"authors": [
66
"killme2008 <[email protected]>"

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 0.5.5 日期:2015 年 6 月 29 日
2+
* AV.Promise 启用兼容 Promise+ 模式。
3+
* 增加 AV.BigQuery 相关 API 用于发起离线分析和查询结果等。
4+
* 修正 AV.Query 的 get 方法在遇到 undefined objectId 运行结果不符合预期的 Bug
5+
* 修复 AV.File 无法作为数组保存的 Bug。
6+
17
# 0.5.4 日期:2015 年 5 月 14 日
28
* 紧急修复 localStorage 模块大小写名称错误。
39

dist/av-core-mini.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-core.js

Lines changed: 158 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,7 @@
16231623
route !== "cloudQuery" &&
16241624
route !== "qiniu" &&
16251625
route !== "statuses" &&
1626+
route !== "bigquery" &&
16261627
route !== 'search/select' &&
16271628
route !== 'subscribe/statuses/count' &&
16281629
route !== 'subscribe/statuses' &&
@@ -3410,6 +3411,9 @@
34103411
* </p>
34113412
*/
34123413
AV.Relation = function(parent, key) {
3414+
if (! _.isString(key)) {
3415+
throw TypeError('key must be a string');
3416+
}
34133417
this.parent = parent;
34143418
this.key = key;
34153419
this.targetClassName = null;
@@ -3548,7 +3552,7 @@
35483552

35493553
_.extend(AV.Promise, /** @lends AV.Promise */ {
35503554

3551-
_isPromisesAPlusCompliant: false,
3555+
_isPromisesAPlusCompliant: true,
35523556

35533557
/**
35543558
* Returns true iff the given object fulfils the Promise interface.
@@ -4449,6 +4453,10 @@
44494453

44504454
AV.File.prototype = {
44514455

4456+
toJSON: function() {
4457+
return AV._encode(this);
4458+
},
4459+
44524460
/**
44534461
* Returns the ACL for this file.
44544462
* @returns {AV.ACL} An instance of AV.ACL.
@@ -7501,11 +7509,17 @@
75017509
* @param {Object} options A Backbone-style options object.
75027510
*/
75037511
get: function(objectId, options) {
7512+
if(!objectId) {
7513+
var errorObject = new AV.Error(AV.Error.OBJECT_NOT_FOUND,
7514+
"Object not found.");
7515+
return AV.Promise.error(errorObject);
7516+
}
7517+
75047518
var self = this;
75057519
self.equalTo('objectId', objectId);
75067520

75077521
return self.first().then(function(response) {
7508-
if (response) {
7522+
if (!AV._.isEmpty(response)) {
75097523
return response;
75107524
}
75117525

@@ -9023,3 +9037,145 @@
90239037
}
90249038
});
90259039
})(this);
9040+
9041+
(function(root) {
9042+
root.AV = root.AV || {};
9043+
var AV = root.AV;
9044+
var _ = AV._;
9045+
9046+
/**
9047+
* @namespace 包含了使用了 LeanCloud
9048+
* <a href='/docs/bigquery_guide.html'>离线数据分析功能</a>的函数。
9049+
* <p><strong><em>
9050+
* 部分函数仅在云引擎运行环境下有效。
9051+
* </em></strong></p>
9052+
*/
9053+
AV.BigQuery = AV.BigQuery || {};
9054+
9055+
_.extend(AV.BigQuery, /** @lends AV.BigQuery */ {
9056+
9057+
/**
9058+
* 开始一个 BigQuery 任务。结果里将返回 Job id,你可以拿得到的 id 使用
9059+
* AV.BigQuery.JobQuery 查询任务状态和结果。
9060+
* @param {Object} jobConfig 任务配置的 JSON 对象,例如:<code><pre>
9061+
* { "sql" : "select count(*) as c,gender from _User group by gender",
9062+
* "saveAs": {
9063+
* "className" : "UserGender",
9064+
* "limit": 1
9065+
* }
9066+
* }
9067+
* </pre></code>
9068+
* sql 指定任务执行的 SQL 语句, saveAs(可选) 指定将结果保存在哪张表里,limit 最大 1000。
9069+
* @param {Object} options A Backbone-style options object
9070+
* options.success, if set, should be a function to handle a successful
9071+
* call to a cloud function. options.error should be a function that
9072+
* handles an error running the cloud function. Both functions are
9073+
* optional. Both functions take a single argument.
9074+
* @return {AV.Promise} A promise that will be resolved with the result
9075+
* of the function.
9076+
*/
9077+
startJob: function(jobConfig, options) {
9078+
if(!jobConfig || !jobConfig.sql) {
9079+
throw new Error('Please provide the sql to run the job.');
9080+
}
9081+
var data = {
9082+
jobConfig: jobConfig,
9083+
appId: AV.applicationId
9084+
}
9085+
var request = AV._request("bigquery", 'jobs', null, 'POST',
9086+
AV._encode(data, null, true));
9087+
9088+
return request.then(function(resp) {
9089+
return AV._decode(null, resp).id;
9090+
})._thenRunCallbacks(options);
9091+
},
9092+
9093+
/**
9094+
* 监听 BigQuery 任务事件,目前仅支持 end 事件,表示任务完成。
9095+
* <p><strong><em>
9096+
* 仅在云引擎运行环境下有效。
9097+
* </em></strong></p>
9098+
* @param {String} event 监听的事件,目前仅支持 'end' ,表示任务完成
9099+
* @param {Function} 监听回调函数,接收 (err, id) 两个参数,err 表示错误信息,
9100+
* id 表示任务 id。接下来你可以拿这个 id 使用AV.BigQuery.JobQuery 查询任务状态和结果。
9101+
*
9102+
*/
9103+
on: function(event, cb) {
9104+
}
9105+
});
9106+
9107+
/**
9108+
* 创建一个对象,用于查询 BigQuery 任务状态和结果。
9109+
* @class
9110+
* @param {String} id 任务 id
9111+
* @since 0.5.5
9112+
*/
9113+
AV.BigQuery.JobQuery = function(id, className) {
9114+
if(!id) {
9115+
throw new Error('Please provide the job id.');
9116+
}
9117+
this.id = id;
9118+
this.className = className;
9119+
this._skip = 0;
9120+
this._limit = 100;
9121+
};
9122+
9123+
AV.BigQuery.JobQuery.prototype = {
9124+
9125+
/**
9126+
* Sets the number of results to skip before returning any results.
9127+
* This is useful for pagination.
9128+
* Default is to skip zero results.
9129+
* @param {Number} n the number of results to skip.
9130+
* @return {AV.Query} Returns the query, so you can chain this call.
9131+
*/
9132+
skip: function(n) {
9133+
this._skip = n;
9134+
return this;
9135+
},
9136+
9137+
/**
9138+
* Sets the limit of the number of results to return. The default limit is
9139+
* 100, with a maximum of 1000 results being returned at a time.
9140+
* @param {Number} n the number of results to limit to.
9141+
* @return {AV.Query} Returns the query, so you can chain this call.
9142+
*/
9143+
limit: function(n) {
9144+
this._limit = n;
9145+
return this;
9146+
},
9147+
9148+
/**
9149+
* 查询任务状态和结果,任务结果为一个 JSON 对象,包括 status 表示任务状态, totalCount 表示总数,
9150+
* results 数组表示任务结果数组,previewCount 表示可以返回的结果总数,任务的开始和截止时间
9151+
* startTime、endTime 等信息。
9152+
*
9153+
* @param {Object} options A Backbone-style options object
9154+
* options.success, if set, should be a function to handle a successful
9155+
* call to a cloud function. options.error should be a function that
9156+
* handles an error running the cloud function. Both functions are
9157+
* optional. Both functions take a single argument.
9158+
* @return {AV.Promise} A promise that will be resolved with the result
9159+
* of the function.
9160+
*
9161+
*/
9162+
find: function(options) {
9163+
var params = {
9164+
skip: this._skip,
9165+
limit: this._limit
9166+
};
9167+
9168+
var request = AV._request("bigquery", 'jobs', this.id, "GET",
9169+
params);
9170+
var self = this;
9171+
return request.then(function(response) {
9172+
if(response.error) {
9173+
return AV.Promise.error(new AV.Error(response.code, response.error));
9174+
}
9175+
return AV.Promise.as(response);
9176+
})._thenRunCallbacks(options);
9177+
}
9178+
9179+
};
9180+
9181+
}(this));

dist/av-mini.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)