Skip to content

Commit

Permalink
Merge pull request #83 from ifanrx/update-sdk-table
Browse files Browse the repository at this point in the history
开发文档全面更新 tableName  说明
  • Loading branch information
arcturus011 authored Jan 10, 2019
2 parents f234188 + 5602835 commit ce96578
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 96 deletions.
10 changes: 5 additions & 5 deletions cloud-function/node-sdk/schema/geo.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var polygon = new BaaS.GeoPolygon([point1, point2, point3, point1])
**请求示例**

```js
var Product = new BaaS.TableObject(tableID)
var Product = new BaaS.TableObject(tableName)
var product = Product.create()

// 保存一个点
Expand All @@ -55,7 +55,7 @@ product.set('origin', polygon).save()
```js
// 查找当前用户所属小区

var Neighbourhood = new BaaS.TableObject(neighbourhoodTableID)
var Neighbourhood = new BaaS.TableObject(neighbourhoodTableName)

var query = new BaaS.Query()

Expand All @@ -70,7 +70,7 @@ Neighbourhood.setQuery(query).find()
```js
// 查找在距离用户 radius 千米范围内的饭店

var Restaurant = new BaaS.TableObject(restaurantTableID)
var Restaurant = new BaaS.TableObject(restaurantTableName)

// geoField 为 restaurant 表中定义地理位置的字段名
query.withinCircle('geoField', point, radius)
Expand All @@ -84,7 +84,7 @@ Restaurant.setQuery(query).find()
```js
// 查找距离用户 minDistance 千米外,maxDistance 千米内的所有饭店

var Restaurant = new BaaS.TableObject(restaurantTableID)
var Restaurant = new BaaS.TableObject(restaurantTableName)

// geoField 为 restaurant 表中定义地理位置的字段名,point 为圆点,minDistance 不指定默认为 0
query.withinRegion('geoField', point, maxDistance, minDistance)
Expand All @@ -98,7 +98,7 @@ Restaurant.setQuery(query).find()
```js
// 查找某个小区内的所有饭店

var Neighbourhood = new BaaS.TableObject(neighbourhoodTableID)
var Neighbourhood = new BaaS.TableObject(neighbourhoodTableName)

Neighbourhood.get(recordID).then(res => {
var neighbourhood = res.data
Expand Down
4 changes: 2 additions & 2 deletions cloud-function/node-sdk/schema/get-record-detail.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ tableID 和 tableName 二选一,不能同时存在
**请求示例**

```js
let tableID = 10
let tableName = 'product'
let recordID = '59897882ff650c0477f00485'

let Product = new BaaS.TableObject(tableID)
let Product = new BaaS.TableObject(tableName)

Product.get(recordID).then(res => {
// success
Expand Down
4 changes: 2 additions & 2 deletions cloud-function/node-sdk/schema/limit-and-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
默认 limit 为 20, offset 为 0,我们也可以手动指定 limit 和 offset 来控制。例如,每页展示 100 条数据,需要获取第五页的数据,将 limit 设置为 100、offset 设置为 400 即可。limit 最大可设置为 1000。

```js
var Product = new BaaS.TableObject(tableID)
var Product = new BaaS.TableObject(tableName)

var query = new BaaS.Query()
query.compare('amount', '>', 0)
Expand All @@ -27,7 +27,7 @@ Product.setQuery(query).limit(10).offset(0).find().then(res => {
使用 orderBy 来控制使用升序或降序获取数据列表。

```js
var Product = new BaaS.TableObject(tableID)
var Product = new BaaS.TableObject(tableName)

var query = new BaaS.Query()
query.compare('amount', '>', 0)
Expand Down
6 changes: 3 additions & 3 deletions cloud-function/node-sdk/schema/operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tableID 和 tableName 二选一,不能同时存在

```js

let MyTableObject = new BaaS.TableObject(tableID)
let MyTableObject = new BaaS.TableObject(tableName)
MyTableObject.exportData('json', 'all').then(res => {
// success
}, err => {
Expand Down Expand Up @@ -73,7 +73,7 @@ res.data:

```js
/* url */
let MyTableObject = new BaaS.TableObject(tableID)
let MyTableObject = new BaaS.TableObject(tableName)
MyTableObject.importData({dataFileUrl: dataUrl}, 'csv').then(res => {
// success
}, err => {
Expand All @@ -96,7 +96,7 @@ BaaS.request.get(dataUrl).then(res => {

/* Buffer */
BaaS.request.get(dataUrl).then(res => {
let MyTable = new BaaS.TableObject(tableID)
let MyTable = new BaaS.TableObject(tableName)
MyTable.importData({dataFile: Buffer.from(res.data)}, 'csv').then(res => {
// success
}, err => {
Expand Down
4 changes: 2 additions & 2 deletions cloud-function/node-sdk/schema/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let query = new BaaS.Query()
//...

// 应用查询对象
let Product = new BaaS.TableObject(tableID)
let Product = new BaaS.TableObject(tableName)
Product.setQuery(query).find().then(res => {
// success
}, err => {
Expand Down Expand Up @@ -490,7 +490,7 @@ let orQuery = BaaS.Query.or(andQuery, query3)

## 获取符合筛选条件的数据总数
```javascript
let Product = new BaaS.TableObject(tableID)
let Product = new BaaS.TableObject(tableName)
let query = new BaaS.Query()

// 设置查询条件
Expand Down
8 changes: 4 additions & 4 deletions cloud-function/node-sdk/schema/select-and-expand.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
**在 get 方法中使用**

```js
var Product = new BaaS.TableObject(tableID)
var Product = new BaaS.TableObject(tableName)
var recordID = 'xxxxxxxxx' // 指定数据行 id

// 规定返回特定字段
Expand All @@ -24,7 +24,7 @@ Product.select(['-created_at', '-created_by']).get(recordID)
**在 find 方法中使用**

```js
var Product = new BaaS.TableObject(tableID)
var Product = new BaaS.TableObject(tableName)

var query = new BaaS.Query()
query.compare('amount', '>', 0)
Expand Down Expand Up @@ -91,13 +91,13 @@ Product.setQuery(query).select(['-created_at', '-created_by']).find()
### 使用方法
**在 get 方法中使用**
```js
var Product = new BaaS.TableObject(tableID)
var Product = new BaaS.TableObject(tableName)
Product.expand(['created_by', 'pointer_value']).get('5acc2904da6b737322a82f78')
```

**在 find 方法中使用**
```js
var Product = new BaaS.TableObject(tableID)
var Product = new BaaS.TableObject(tableName)

var query = new BaaS.Query()
query.compare('amount', '>', 0)
Expand Down
8 changes: 4 additions & 4 deletions cloud-function/node-sdk/schema/update-record.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ product.update().then(res=>{
```js
product.append('desc', ['big'])
// or
product.append('desc, 'big')
product.append('desc', 'big')
```

#### _待插入的数组_ 中不包含在原数组的数据加到原数组末尾
Expand All @@ -254,7 +254,7 @@ product.append('desc, 'big')
```js
product.uAppend('desc', ['sweet'])
// or
product.uAppend('desc, 'sweet')
product.uAppend('desc', 'sweet')
```

#### 从原数组中删除指定的值
Expand Down Expand Up @@ -322,7 +322,7 @@ order.update()
**请求示例**

```js
let MyTableObject = new BaaS.TableObject(tableID)
let MyTableObject = new BaaS.TableObject(tableName)

let query = new BaaS.Query()

Expand Down Expand Up @@ -385,7 +385,7 @@ then 回调中的 res 对象结构如下:
### 按条件批量更新时不触发触发器

```js
let MyTableObject = new BaaS.TableObject(tableID)
let MyTableObject = new BaaS.TableObject(tableName)

let query = new BaaS.Query()

Expand Down
4 changes: 2 additions & 2 deletions dashboard/cloud-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ exports.main = function functionName(event, callback) {

```js
exports.main = function testSchema(event, callback) {
let tableID = 233
let tableName = 'product'
let recordID = "5a7291050fc321091e97bcdc"
let table = new BaaS.TableObject(tableID)
let table = new BaaS.TableObject(tableName)
table.find().then(res => {
callback(null, res.data)
}, err => {
Expand Down
10 changes: 5 additions & 5 deletions js-sdk/schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
通过 `TableRecord` 实例的 `set``save` 方法,可以完成数据行的创建。

> **info**
> SDK 1.2.0 版本已支持通过数据表名实例化 TableObject,如操作数据表名为 'product' 的数据表,可进行如下实例化:new wx.BaaS.TableObject('product')
> SDK 1.2.0 以下(不包含 1.2.0 )版本仅支持通过数据表 ID 实例化 TableObject,如操作数据表名为 10 的数据表,可进行如下实例化:new wx.BaaS.TableObject(10)

```js
let tableID = 10
// 通过 `tableID` 实例化一个 `TableObject` 对象,操作该对象即相当于操作对应的数据表
let Product = new wx.BaaS.TableObject(tableID)
let tableName = 'product'
// 通过 `tableName` 实例化一个 `TableObject` 对象,操作该对象即相当于操作对应的数据表
let Product = new wx.BaaS.TableObject(tableName)
// 本地创建一条空记录
let product = Product.create() // product 为 TableRecord 实例

Expand Down Expand Up @@ -108,7 +108,7 @@ res 结构如下:

```js
// 假设 product 表有一个字段为 product_id ,其中数据的格式形如 '112233'
let Product = new wx.BaaS.TableObject(tableID)
let Product = new wx.BaaS.TableObject(tableName)
var query = new wx.BaaS.Query()

// 查找产品 ID 以 11 开头,以 33 结尾的产品
Expand Down
28 changes: 14 additions & 14 deletions js-sdk/schema/create-record.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

### 操作步骤

1.通过 `tableID` 实例化一个 `TableObject` 对象,操作该对象即相当于操作对应的数据表
1.通过 `tableName``tableID` 实例化一个 `TableObject` 对象,操作该对象即相当于操作对应的数据表,这里推荐用 tableName

`let MyTableObject = new wx.BaaS.TableObject(tableID)`
`let MyTableObject = new wx.BaaS.TableObject(tableName)`

**参数说明**

| 参数 | 类型 | 必填 | 说明 |
| :----- | :----- | :-- | :---|
| tableID | Number || 数据表 ID |
tableName 和 tableID 二选一,不能同时存在

> **info**
> SDK 1.2.0 版本已支持通过数据表名实例化 TableObject,如操作数据表名为 'product' 的数据表,可进行如下实例化:new wx.BaaS.TableObject('product')
| 参数 | 类型 | 必填 | 说明 |
| :----- | :----- | :-- | :-- |
| tableID | Number || 数据表的 ID |
| tableName | String || 数据表名(SDK >= 1.2.0) |

2.本地创建一条空记录

Expand Down Expand Up @@ -62,9 +62,9 @@ MyRecord.set(key2, value2)
**请求示例**

```js
//tableID10 的数据表插入一条记录
let tableID = 10
let Product = new wx.BaaS.TableObject(tableID)
//tableName'product' 的数据表插入一条记录
let tableName = 'product'
let Product = new wx.BaaS.TableObject(tableName)
let product = Product.create()

// 设置方式一
Expand Down Expand Up @@ -229,23 +229,23 @@ array 类型数据中的元素类型,要与预先在知晓云平台设定的

```js
// 元素类型为 integer
let Table = new wx.BaaS.TableObject(tableID)
let Table = new wx.BaaS.TableObject(tableName)
let record = Table.create()
record.set('array_int', [1, 2, 3])
record.save()
```

```js
// 元素类型为 string
let Table = new wx.BaaS.TableObject(tableID)
let Table = new wx.BaaS.TableObject(tableName)
let record = Table.create()
record.set('array_str', ['a', 'b', 'c'])
record.save()
```

```js
// 元素类型为 object
let Table = new wx.BaaS.TableObject(tableID)
let Table = new wx.BaaS.TableObject(tableName)
let record = Table.create()
let obj_1 = {a: 10}
let obj_2 = {b: 20}
Expand Down Expand Up @@ -363,7 +363,7 @@ SDK **1.4.0** 及以上版本支持批量新增数据项。
**请求示例**

```js
let MyTableObject = new wx.BaaS.TableObject(tableID)
let MyTableObject = new wx.BaaS.TableObject(tableName)

const records = [
{
Expand Down
22 changes: 11 additions & 11 deletions js-sdk/schema/delete-record.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

### 操作步骤

1.通过 `tableID` 实例化一个 `TableObject` 对象,操作该对象即相当于操作对应的数据表
1.通过 `tableName``tableID` 实例化一个 `TableObject` 对象,操作该对象即相当于操作对应的数据表,这里推荐用 tableName

`let MyTableObject = new wx.BaaS.TableObject(tableID)`
`let MyTableObject = new wx.BaaS.TableObject(tableName)`

**参数说明**

| 参数 | 类型 | 必填 | 说明 |
| :----- | :----- | :-- | :---|
| tableID | Number || 数据表 ID |
tableName 和 tableID 二选一,不能同时存在

> **info**
> SDK 1.2.0 版本已支持通过数据表名实例化 TableObject,如操作数据表名为 'product' 的数据表,可进行如下实例化:new wx.BaaS.TableObject('product')
| 参数 | 类型 | 必填 | 说明 |
| :----- | :----- | :-- | :-- |
| tableID | Number || 数据表的 ID |
| tableName | String || 数据表名(SDK >= 1.2.0) |

**返回参数说明**

Expand All @@ -40,11 +40,11 @@

**请求示例**
```js
// 删除 tableID10 的数据表中 recordID 为 59897882ff650c0477f00485 的数据项
let tableID = 10
// 删除 tableName'product' 的数据表中 recordID 为 59897882ff650c0477f00485 的数据项
let tableName = 'product'
let recordID = '59897882ff650c0477f00485'

let Product = new wx.BaaS.TableObject(tableID)
let Product = new wx.BaaS.TableObject(tableName)
Product.delete(recordID).then(res => {
// success
}, err => {
Expand Down Expand Up @@ -82,7 +82,7 @@ SDK 1.4.0 及以上版本支持批量删除数据项。可以通过设置查询
**请求示例**

```js
let MyTableObject = new wx.BaaS.TableObject(tableID)
let MyTableObject = new wx.BaaS.TableObject(tableName)

let query = new wx.BaaS.Query()

Expand Down
10 changes: 5 additions & 5 deletions js-sdk/schema/geo.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var polygon = new wx.BaaS.GeoPolygon([point1, point2, point3, point1])
**请求示例**

```js
var Product = new wx.BaaS.TableObject(tableID)
var Product = new wx.BaaS.TableObject(tableName)
var product = Product.create()

// 保存一个点
Expand All @@ -59,7 +59,7 @@ product.set('origin', polygon).save()
```js
// 查找当前用户所属小区

var Neighbourhood = new wx.BaaS.TableObject(neighbourhoodTableID)
var Neighbourhood = new wx.BaaS.TableObject(neighbourhoodTableName)

var query = new wx.BaaS.Query()

Expand All @@ -74,7 +74,7 @@ Neighbourhood.setQuery(query).find()
```js
// 查找在距离用户 radius 千米范围内的饭店

var Restaurant = new wx.BaaS.TableObject(restaurantTableID)
var Restaurant = new wx.BaaS.TableObject(restaurantTableName)

// geoField 为 restaurant 表中定义地理位置的字段名
query.withinCircle('geoField', point, radius)
Expand All @@ -88,7 +88,7 @@ Restaurant.setQuery(query).find()
```js
// 查找距离用户 minDistance 千米外,maxDistance 千米内的所有饭店

var Restaurant = new wx.BaaS.TableObject(restaurantTableID)
var Restaurant = new wx.BaaS.TableObject(restaurantTableName)

// geoField 为 restaurant 表中定义地理位置的字段名,point 为圆点,minDistance 不指定默认为 0
query.withinRegion('geoField', point, maxDistance, minDistance)
Expand All @@ -102,7 +102,7 @@ Restaurant.setQuery(query).find()
```js
// 查找某个小区内的所有饭店

var Neighbourhood = new wx.BaaS.TableObject(neighbourhoodTableID)
var Neighbourhood = new wx.BaaS.TableObject(neighbourhoodTableName)

Neighbourhood.get(recordID).then(res => {
var neighbourhood = res.data
Expand Down
Loading

0 comments on commit ce96578

Please sign in to comment.