반응형

 

javascript로 dynamoDB 연동중

조회 후 리턴 정보가 object로 되어 있길래 

찾아보니 unmarshall 하는 게 있었다.

 

https://docs.aws.amazon.com/ko_kr/amazondynamodb/latest/developerguide/Introduction.html

 

What is Amazon DynamoDB? - Amazon DynamoDB

이 페이지에 작업이 필요하다는 점을 알려 주셔서 감사합니다. 실망시켜 드려 죄송합니다. 잠깐 시간을 내어 설명서를 향상시킬 수 있는 방법에 대해 말씀해 주십시오.

docs.aws.amazon.com

공식문서엔 관련 내용이 없다. 

 

마샬링이란 한 객체의 메모리에서의 표현방식을 저장 또한 전송에 적합한 다른 데이터 형식으로 변환하는 과정이다.

DynamoDB에서 전송에 적합에 데이터 형식으로 변환해서 보내준다고 이해하면 되겠다.

조회 결과의 데이터는 object로 사용하려면 언마샬링이 필요하다.

 

https://hwanine.github.io/network/Marshalling/

 

import  { unmarshall } from '@aws-sdk/util-dynamodb';

// marshall된 오프젝트를 unmarshall 함수를 통해 변환해서 사용해야 한다.
const dataRow = unmarshall(data.Items[0]);

 

 

공통 조회에서 결과 리턴전에 처리하는 것도 고려해볼 만하다.

 

const send = async (queryParams) => {
  try {
    const data = await ddbDocClient.send(new ExecuteStatementCommand(queryParams));
    // console.log(data.Items[0]);
    // return unmarshall(data.Items);
    return {Items : data.Items.map(item => unmarshall(item)) };
    // return data
  } catch (err) {
    return {
      message: err.message,
      httpStatusCode: err.$metadata.httpStatusCode
    };
  }
};

 

 

참고

https://www.tabnine.com/code/javascript/functions/marshall

반응형

+ Recent posts