update method
更新数据
Implementation
Future<DbUpdateResponse> update(dynamic data) async {
if (_id == null) {
return DbUpdateResponse(
code: CloudBaseExceptionCode.INVALID_PARAM,
message: 'docId不能为空',
);
}
if (data == null) {
return DbUpdateResponse(
code: CloudBaseExceptionCode.INVALID_PARAM,
message: '参数必需是非空对象',
);
}
if (data['_id'] != null) {
return DbUpdateResponse(
code: CloudBaseExceptionCode.INVALID_PARAM,
message: '不能更新_id的值',
);
}
data = Serializer.encode(data);
Map<String, dynamic> query = {'_id': this._id};
Map<String, dynamic> params = {
'query': query,
'data': data,
'multi': false,
'merge': true,
'upsert': false,
'interfaceCallSource': 'SINGLE_UPDATE_DOC',
};
CloudBaseResponse res = await _docRequest(
'database.updateDocument',
params,
);
if (res.code != null) {
return DbUpdateResponse(
code: res.code,
message: res.message,
requestId: res.requestId,
);
}
return DbUpdateResponse(
requestId: res.requestId,
updateId: res.data['upserted_id'],
updated: res.data['updated'],
);
}