跳到主要内容

set 更新单条记录

set 根据主键更新单条记录。

Luwak >= 3.0.0, asm.so >= 0.1.4

API

公共参数 metas 对象

名称类型描述
tokenstring访问令牌,当需要授权才能访问时为必填
signaturestring签名
appKeystring当需要签名时为必填
timestampstring, number时间戳,当校验时间误差范围时为必填

请求参数

名称类型描述
methodstringAPI 名称
paramsarrayAPI 参数

method 命名规范是 $entity.set

params 参数是一个数组,包含一个主键值和一个数据对象。

响应结果

返回受影响的行数

示例

场景描述

更新品牌表中 id 为 1 的记录。

请求

{
"jsonrpc": "2.0",
"method": "smartPanda.mdh.brand.set",
"params": [
1,
{
"name": "Brand Name",
"disabled": 1
}
],
"metas": {
"token": "44ea16b7-3aa1-41a5-81da-8ee9d2b840c2",
"signature": "0e6767b6b0adf7812078e761beda657b",
"appKey": "NSEA4ETIpBlyB2l9",
"timestamp": 1740640461312
},
"id": "c087d285-c216-41d7-90f8-8ace5e88a57e"
}

响应

{
"jsonrpc": "2.0",
"result": 1,
"id": "c087d285-c216-41d7-90f8-8ace5e88a57e"
}

实体定义

smart_panda 库中 brand 表的定义如下

CREATE TABLE `brand`
(
`id` int AUTO_INCREMENT,
`name` varchar(20),
PRIMARY KEY (`id`)
);

entity 名称是 smartPanda.mdh.brand

实际执行的 SQL

Prepare   UPDATE smart_panda.brand SET name = ? WHERE id = ?
Execute UPDATE smart_panda.brand SET name = 'Brand Name' WHERE id = 1