Skip to content

对外数据 CRUD + Schema(Token 鉴权) ( data ) 相关文档

列表 ✅

请求地址:GET /data/:table

参数:

参数名位置类型格式化必填说明
tableparamsstring(无)
pagequerynumber(无)
sizequerynumber(无)
orderquerystring(无)
qquerystring(无)

使用示例:

javascript
// 列表查询 - /data/users 

headers = {
  "Authorization": "Bearer oa_testtoken_bfz7clvk2xp"
}
input = {};
output = {
  "success": true,
  "data": {
    "rows": [
      {
        "id": 2,
        "name": "bob",
        "age": 25
      }
    ],
    "total": 1,
    "page": 1,
    "size": 20
  }
};

表结构 ✅

请求地址:GET /data/:table/schema

参数:

参数名位置类型格式化必填说明
tableparamsstring(无)

使用示例:

javascript
// 表结构 - /data/users/schema 

headers = {
  "Authorization": "Bearer oa_testtoken_bfz7clvk2xp"
}
input = {};
output = {
  "success": true,
  "data": {
    "id": 1,
    "name": "users",
    "label": "用户表",
    "primaryKey": "id",
    "fields": [
      {
        "name": "id",
        "label": "id",
        "sqliteType": "INTEGER",
        "jsonType": "integer",
        "nullable": true,
        "defaultValue": null,
        "isPrimary": true,
        "isAutoIncrement": true,
        "isHidden": false,
        "isReadonly": false
      },
      {
        "name": "name",
        "label": "name",
        "sqliteType": "TEXT",
        "jsonType": "string",
        "nullable": true,
        "defaultValue": null,
        "isPrimary": false,
        "isAutoIncrement": false,
        "isHidden": false,
        "isReadonly": false
      },
      {
        "name": "age",
        "label": "age",
        "sqliteType": "INTEGER",
        "jsonType": "integer",
        "nullable": true,
        "defaultValue": null,
        "isPrimary": false,
        "isAutoIncrement": false,
        "isHidden": false,
        "isReadonly": false
      }
    ],
    "isPublished": true,
    "isEditable": true,
    "note": "用户信息表",
    "createdAt": 1783640695280,
    "updatedAt": 1783640695299
  }
};

单条 ✅

请求地址:GET /data/:table/records/:pk

参数:

参数名位置类型格式化必填说明
tableparamsstring(无)
pkparamsstring(无)

使用示例:

javascript
// 查询单条 - /data/users/records/2 

headers = {
  "Authorization": "Bearer oa_testtoken_bfz7clvk2xp"
}
input = {};
output = {
  "success": true,
  "data": {
    "id": 2,
    "name": "bob",
    "age": 25
  }
};

创建 ✅

请求地址:POST /data/:table/records

参数:

参数名位置类型格式化必填说明
tableparamsstring(无)

使用示例:

javascript
// 创建记录 - /data/users/records 

headers = {
  "Authorization": "Bearer oa_testtoken_bfz7clvk2xp"
}
input = {
  "name": "bob",
  "age": 25
};
output = {
  "success": true,
  "data": {
    "id": 2,
    "name": "bob",
    "age": 25
  }
};

更新 ✅

请求地址:PUT /data/:table/records/:pk

参数:

参数名位置类型格式化必填说明
tableparamsstring(无)
pkparamsstring(无)

使用示例:

javascript
// 更新记录 - /data/users/records/2 

headers = {
  "Authorization": "Bearer oa_testtoken_bfz7clvk2xp"
}
input = {
  "age": 26
};
output = {
  "success": true,
  "data": {
    "success": true
  }
};

删除 ✅

请求地址:DELETE /data/:table/records/:pk

参数:

参数名位置类型格式化必填说明
tableparamsstring(无)
pkparamsstring(无)

使用示例:

javascript
// 删除记录 - /data/users/records/2 

headers = {
  "Authorization": "Bearer oa_testtoken_bfz7clvk2xp"
}
input = {};
output = {
  "success": true,
  "data": {
    "success": true
  }
};

自增 ✅

请求地址:POST /data/:table/incr

参数:

参数名位置类型格式化必填说明
tableparamsstring(无)
pkbodystring(无)
fieldbodystring(无)
countbodynumber(无)

使用示例:

javascript
// 自增 - /data/users/incr 

headers = {
  "Authorization": "Bearer oa_testtoken_bfz7clvk2xp"
}
input = {
  "pk": 2,
  "field": "age",
  "count": 1
};
output = {
  "success": true,
  "data": {
    "success": true
  }
};

新建模型(token) ✅

请求地址:POST /data/_schema/tables

参数:

参数名位置类型格式化必填说明
namebodystring(无)
labelbodystring(无)
fieldsbodyarray(无)
notebodystring(无)
autoTimestampsbodyboolean(无)

使用示例:

javascript
// 通过 Token 新建模型 - /data/_schema/tables 

headers = {
  "Authorization": "Bearer oa_testtoken_bfz7clvk2xp"
}
input = {
  "name": "products",
  "label": "商品",
  "fields": [
    {
      "name": "id",
      "jsonType": "integer",
      "isPrimary": true,
      "isAutoIncrement": true
    },
    {
      "name": "name",
      "jsonType": "string"
    }
  ]
};
output = {
  "success": true,
  "data": {
    "id": 3,
    "name": "products",
    "label": "商品",
    "primaryKey": "id",
    "fields": [
      {
        "name": "id",
        "label": "id",
        "sqliteType": "INTEGER",
        "jsonType": "integer",
        "nullable": true,
        "defaultValue": null,
        "isPrimary": true,
        "isAutoIncrement": true,
        "isHidden": false,
        "isReadonly": false
      },
      {
        "name": "name",
        "label": "name",
        "sqliteType": "TEXT",
        "jsonType": "string",
        "nullable": true,
        "defaultValue": null,
        "isPrimary": false,
        "isAutoIncrement": false,
        "isHidden": false,
        "isReadonly": false
      }
    ],
    "isPublished": true,
    "isEditable": true,
    "note": null,
    "createdAt": 1783640695443,
    "updatedAt": 1783640695443
  }
};

加字段(token) ✅

请求地址:POST /data/_schema/tables/:table/fields

参数:

参数名位置类型格式化必填说明
tableparamsstring(无)
fieldbodyrecord(无)

使用示例:

javascript
// 通过 Token 加字段 - /data/_schema/tables/products/fields 

headers = {
  "Authorization": "Bearer oa_testtoken_bfz7clvk2xp"
}
input = {
  "field": {
    "name": "price",
    "jsonType": "number"
  }
};
output = {
  "success": true,
  "data": {
    "id": 3,
    "name": "products",
    "label": "商品",
    "primaryKey": "id",
    "fields": [
      {
        "name": "id",
        "label": "id",
        "sqliteType": "INTEGER",
        "jsonType": "integer",
        "nullable": true,
        "defaultValue": null,
        "isPrimary": true,
        "isAutoIncrement": true,
        "isHidden": false,
        "isReadonly": false
      },
      {
        "name": "name",
        "label": "name",
        "sqliteType": "TEXT",
        "jsonType": "string",
        "nullable": true,
        "defaultValue": null,
        "isPrimary": false,
        "isAutoIncrement": false,
        "isHidden": false,
        "isReadonly": false
      },
      {
        "name": "price",
        "label": "price",
        "sqliteType": "REAL",
        "jsonType": "number",
        "nullable": true,
        "defaultValue": null,
        "isPrimary": false,
        "isAutoIncrement": false,
        "isHidden": false,
        "isReadonly": false
      }
    ],
    "isPublished": true,
    "isEditable": true,
    "note": null,
    "createdAt": 1783640695443,
    "updatedAt": 1783640695447
  }
};

基于 MIT 协议发布