CRUD 처리할 때(특히 UPDATE!) 있어도 되고 없어도 되는 파라미터를 처리할 경우
if (email !== undefined) {
if (arg.length === 0) {
condition += 'email = ?';
} else {
condition += ', email = ?';
}
arg.push(email);
}
if (paymentStateType !== undefined) {
if (arg.length === 0) {
condition += 'paymentStateType = ?';
} else {
condition += ', paymentStateType = ?';
}
arg.push(paymentStateType);
}
sql = `UPDATE exam_reception SET ${condition} WHERE examReceptionId =?`;
arg.push(examReceptionId);
요런식으로 파라미터에 있는 키만 업데이트 시키면 됨
하지만 모든 파라미터가 있어야하는 경우
그냥 일케 원래대로 처리하면 됨
sql = `UPDATE exam_reception SET postalCode = ?,
address = ?, deliveryCode = ?, receiverName = ?,
receiverPhoneNum = ?, deliveryType = ?, deliveryOrderDate = ?
WHERE examReceptionId =?`;
arg = [
postalCode,
address,
deliveryCode,
receiverName,
receiverPhoneNum,
deliveryType,
deliveryOrderDate,
examReceptionId,
];
await conn.query(sql, arg);