数据表操作
创建数据表
接口
POST https://cloud.minapp.com/oserve/v1.8/table/
提交参数
参数 row_read_perm 和 row_write_perm 控制数据表数据的读写权限,读权限表示用户是否有权限获取数据,写权限表示用户是否有权限更新数据。
参数 write_perm 控制数据表的写权限,即表示用户是否有权限创建数据。
权限参数的说明:
所有人(临时用户 + 登录用户)可写/所有人(登录用户 + 未登录用户)可读
具体描述与使用场景可参考ACL 访问控制列表。
参数 schema 用于存储数据表字段的元信息,其结构遵循JSON-Table-Schema的描述。
例:
{
"fields": [
{
"name": "field_name",
"type": "string",
"description": "description of field_name",
"constraints": {
"required": true # 设置写入/更新必填选项
},
"default": "hello, world", # 设置默认值
"acl": {
"clientVisibile": true, # 设置客户端可见
"clientReadOnly": true, # 设置客户端只读
"creatorVisible": true # 设置创建者可见
}
}
]
}
数据表列的元信息:
geojson 字段类型必填,值默认为 default
pointer 字段类型必填,表示关联的数据表 ID
type
目前支持 string、integer、number、boolean、array、geojson、file、date、reference(pointer 类型字段)等
items
目前支持 string、integer、number、boolean 等
coordinate_type
目前支持 wgs84(地球坐标)、gcj02(火星坐标)
若字段是 array 类型,字段元信息为:
{
"name": "array_field",
"type": "array",
"items": {
"type": "string"
}
}
若字段是 geojson 类型,字段元信息为:
{
"name": "location",
"type": "geojson",
"format": "default",
"coordinate_type": "gcj02"
}
若字段是 pointer 类型,字段元信息为:
{
"name": "pointer",
"type": "reference",
"schema_id": "1"
}
字段权限相关的属性存储在 acl 中:
客户端只读的标志位,true 表示字段在客户端只读,不能被写入/更新
客户端可见的标志位, false 表示字段在客户端不可见
客户端创建者可见的标志位,true 表示字段在客户端只有创建者可见
代码示例
curl -X POST \
-H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
-H "Content-Type: application/json" \
-d '{
"name": "Table199",
"schema": {
"fields": [
{
"name": "String",
"type": "string"
}
]
},
"row_read_perm": ["user:*"],
"row_write_perm": ["user:*"],
"write_perm": ["user:*"]
}' \
https://cloud.minapp.com/oserve/v1.8/table/
var request = require("request");
var options = { method: 'POST',
url: 'https://cloud.minapp.com/oserve/v1.8/table/',
headers:
{ 'Content-Type': 'application/json',
Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' },
body:
{ name: 'Table199',
schema: { fields: [ { name: 'String', type: 'string' } ] },
row_read_perm: [ 'user:*' ],
row_write_perm: [ 'user:*' ],
write_perm: [ 'user:*' ] },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
返回示例
{
"id": 1,
"name": "Table",
"protected_fields": null,
"schema": {
"fields": [
{
"description": "id",
"name": "id",
"type": "id"
},
{
"description": "created_by",
"name": "created_by",
"type": "integer"
},
{
"description": "created_at",
"name": "created_at",
"type": "integer"
},
{
"description": "updated_at",
"name": "updated_at",
"type": "integer"
},
{
"name": "String",
"type": "string",
"description": "string"
}
]
},
"write_perm": [
"user:*"
],
"default_row_perm": {
"_read_perm": [
"user:*"
],
"_write_perm": [
"user:*"
]
},
"created_at": 1519538564,
"updated_at": 1519640477
}
info 字段如 id、created_by、created_at、updated_at 为自动添加的内置字段
返回参数说明
内置表的保护字段,若数据表不是内置表,该字段为 null
状态码说明
201
: 修改成功
400
: 表名已存在;不合法的数据
获取数据表详情
接口
GET https://cloud.minapp.com/oserve/v1.8/table/:table_id/
代码示例
curl -X GET \
-H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
-H "Content-Type: application/json" \
https://cloud.minapp.com/oserve/v1.8/table/1/
var request = require("request");
var options = { method: 'GET',
url: 'https://cloud.minapp.com/oserve/v1.8/table/1/',
headers:
{ 'Content-Type': 'application/json',
Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
返回示例
{
"id": 1,
"name": "Table",
"protected_fields": null,
"schema": {
"fields": [
{
"name": "String",
"type": "string"
}
]
},
"write_perm": [
"user:*"
],
"default_row_perm": {
"_read_perm": [
"user:*"
],
"_write_perm": [
"user:*"
]
},
"created_at": 1519538564,
"updated_at": 1519640477
}
状态码说明
200
: 成功
获取数据表列表
接口
GET https://cloud.minapp.com/oserve/v1.8/table/
提交参数
https://cloud.minapp.com/oserve/v1.8/table/?name=Table
代码示例
curl -X GET \
-H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
-H "Content-Type: application/json" \
https://cloud.minapp.com/oserve/v1.8/table/
var request = require("request");
var options = { method: 'GET',
url: 'https://cloud.minapp.com/oserve/v1.8/table/',
headers:
{ 'Content-Type': 'application/json',
Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
返回示例
{
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 1
},
"objects": [
{
"id": 1,
"name": "Table",
"protected_fields": null,
"schema": {
"fields": [
{
"name": "String",
"type": "string"
}
]
},
"write_perm": [
"user:*"
],
"default_row_perm": {
"_read_perm": [
"user:*"
],
"_write_perm": [
"user:*"
]
},
"created_at": 1519538564,
"updated_at": 1519640477
}
]
}
状态码说明
200
: 成功
更新数据表
接口
PUT https://cloud.minapp.com/oserve/v1.8/table/:table_id/
info 数据表更新接口支持一次更新一个或多个字段
代码示例
curl -X PUT \
-H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
-H "Content-Type: application/json" \
-d '{
"name": "table"
}' \
https://cloud.minapp.com/oserve/v1.8/table/1/
var request = require("request");
var options = { method: 'PUT',
url: 'https://cloud.minapp.com/oserve/v1.8/table/1/',
headers:
{ 'Content-Type': 'application/json',
Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' },
body: { name: 'table' },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
返回示例
{
"id": 1,
"name": "table",
"protected_fields": null,
"schema": {
"fields": [
{
"name": "String",
"type": "string"
}
]
},
"write_perm": [
"user:*"
],
"default_row_perm": {
"_read_perm": [
"user:*"
],
"_write_perm": [
"user:*"
]
},
"created_at": 1519538564,
"updated_at": 1519640477
}
状态码说明
200
: 修改成功
400
: 表名已存在;不合法的数据
删除数据表
接口
DELETE https://cloud.minapp.com/oserve/v1.8/table/:table_id/
代码示例
curl -X DELETE \
-H "cookie: {{ cookie }}" \
-H "Content-Type: application/json" \
https://cloud.minapp.com/oserve/v1.8/table/1/
状态码说明
204
: 删除成功
索引
获取数据表下所有的唯一索引
接口
GET https://cloud.minapp.com/oserve/v2.6/schema/:schema_id/index/
代码示例
curl -X GET \
-H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
-H "Content-Type: application/json" \
https://cloud.minapp.com/oserve/v2.6/schema/20/index/
var request = require("request");
var options = { method: 'GET',
url: 'https://cloud.minapp.com/oserve/v2.6/schema/20/index/',
headers:
{ 'Content-Type': 'application/json',
Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
返回示例
{
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 2
},
"objects": [
{
"fields": ["name"],
"index": "name_1"
},
{
"fields": ["name", "description"],
"index": "name_1_description_1"
}
]
}
状态码说明
200:
成功
401:
未授权
建立(联合)唯一索引
接口
POST https://cloud.minapp.com/oserve/v2.6/schema/:schema_id/index/
提交示例
curl -X POST \
-H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
-H "Content-Type: application/json" \
-d '{
"fields":["name","description"]
}' \
https://cloud.minapp.com/oserve/v2.6/schema/20/index/
var request = require("request");
var options = { method: 'POST',
url: 'https://cloud.minapp.com/oserve/v2.6/schema/20/index/',
headers:
{ 'Content-Type': 'application/json',
Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' },
body: { fields: ["name","description"] },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
返回示例
[
{
"fields": ["name"],
"index": "name_1"
},
{
"fields": ["name", "description"],
"index": "name_1_description_1"
}
]
状态码说明
201:
成功
删除索引
接口
DELETE https://cloud.minapp.com/oserve/v2.6/schema/:schema_id/index/:index_name/
代码示例
curl -X DELETE \
-H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
-H "Content-Type: application/json" \
https://cloud.minapp.com/oserve/v2.6/schema/20/index/name_1/
状态码说明
204:
成功