[bug]插入数据成功后,返回的数据id和数据库不一致
wmui opened this issue · comments
wmui commented
当使用create方法插入一条数据:
POST http://127.0.0.1:7001/admin/role
Content-Type: application/json
{
"id": "e32639c7-9573-4f90-828b-be410d58f272",
"name": "test ",
"authority": "100100, 100101"
}
返回的数据
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-download-options: noopen
x-readtime: 38
content-length: 156
Date: Fri, 16 Jun 2023 02:43:22 GMT
Connection: close
{
"success": true,
"data": {
"id": "6",
"name": "test ",
"authority": "100100, 100101",
"updatedAt": "2023-06-16T02:43:22.633Z",
"createdAt": "2023-06-16T02:43:22.633Z"
}
}
数据库里面的id是e32639c7-9573-4f90-828b-be410d58f272
,而create方法返回的是一个索引值
Chen Yangjian commented
什么数据库?id 字段类型是什么
wmui commented
Chen Yangjian commented
知道了,sqlite 数据库有个自带的自增 id,leoric 执行完 insert 默认会用返回的自增 id 去设置对应的 id 字段,一般如果表结构里面 id 类型符合 biginit unsigned,会默认对应到这个自增 id 去
但是在你这个例子里面,这个 id 是不对应的,所以搞错了,我想想怎么处理
Chen Yangjian commented
update执行后返回的是一个number,但是文档写的是spell实例:返回了数字
1
这个其实没错的,update() 本身返回的是 Spell 实例,等同于 Promise,await 之后拿到的是 number,也就是 affectedRows
Chen Yangjian commented