0
가능한 한 상태 비 저장 코드로 시도하고 있습니다. 그러나 관계형 데이터베이스와의 상호 작용에 관해서는 막혔다.관계형 데이터베이스로 상태 비 저장 프로그래밍
var fetchDataFromTable = function(tableName)
{
//dummy result from using mysql library
sqlQuery = "Select * from " + tableName;
return new Promise(function(resolve, reject)
{
con.query(sqlQuery, function(err,body)
{
resolve(body)
})
})
}
var getOrderName = function(checkOrderID,fetchDataFromTable)
{
//Here, I have to hard-code the table name.
fetchFromTable("OrderTable").then(function(result)
{
//dummy function. Can use SQL query instead of looping.
result.forEach(function(index){
if (result[index].orderID == checkOrderID)
return result[index].orderName;
})
})
}
orderName = getOrderName("A123",fetchDataFromTable);
위의 샘플 코드는 특정 결과를 얻기 위해 데이터베이스의 결과에 의존하는 예를 보여줍니다. 이 경우 ".orderID"를 사용하고 있습니다.
제 질문은 스테이트리스라고 생각합니까? 그렇지 않다면 어떻게하면 더 "무국적자"로 만들 수 있습니까?