前情提要&遭遇问题
nestJs 是一个以express为基础的後端框架,该框架可以选择gRPC实作MicroService,并撰写proto作为沟通介面,作为server来说,可以成功透过接收到资料,不过根据proto3三特性,选填、永不null、初始化给预设值,因此导致一情况,null栏位会消失,GET资料,null 栏位直接消,PATCH资料,null栏位送到server端一样消失
补充:
研究历程
解决方案
User Entity
{
"name":string
"phone":string
"age":number
"isVip":boolean
"createdAt":Datetime
"contactInfo":{ //for 支援jsonDB
"address":string
"email":string
}
}
//针对 Patch 资料情境(只送需要更新栏位)
//1. endpoint 解析 FE request 找出 null 的栏位,记录下来,继续往microService丢
//2. 针对巢状资料,需要一次送全部并字串化,因为在DB 是单一 column
-- FE 传送的req
{
"name":"王小明"
"phone":null
"age":number
"isVip":boolean
"createdAt":null
"contactInfo":{
"address":null
"email":"[email protected]"
}
}
-- endpoint 传给 microService 结构
{
"name":"王小明"
"phone":null
"age":number
"isVip":boolean
"createdAt":null
"contactInfo":'{"address":null,"email":"[email protected]"}' //巢状结构字串化
+ "setNullProperty":["phone","createdAt"] //直接纪录需要null栏位
}
--proto
message patchUser{
repreated string setNullProperty = 1
string name = 2
string phone = 3
number age = 4
boolean isVip = 5
string contactInfo = 6
}
ref:
Documentation | NestJS - A progressive Node.js framework
>>: Day 18:501. Find Mode in Binary Search Tree
这次最後一个要分享的Scrum失败经验,就是「没有一位具备经验的Scrum Master」,工程团队...
所有权与函式 将一个变数当作函式的参数传给其他函式,怎样安全的处理所有权 传递数值给函式这样的语义和...
案例说明及适用场景 当有工单的需求时 每一个BOM表都有属於自己的制程,而一个产品可以多个BOM表 ...
情境:有许多 sensor, 一直传送资料,我们想取得最新的资料. create unlogged...
Virtual Judge ZeroJudge 题意 输入粒子经过 t 秒後的速度为 v,求 2t...