Skip to content

Instantly share code, notes, and snippets.

@phanviet
Created March 17, 2020 04:17
Show Gist options
  • Save phanviet/a8776c34dd52866bc02caff21d9dd77c to your computer and use it in GitHub Desktop.
Save phanviet/a8776c34dd52866bc02caff21d9dd77c to your computer and use it in GitHub Desktop.
export const rdsUtils = {
toJsonObject(value) {
const results = value.sqlStatementResults;
const rs = [];
results.forEach((result) => {
const { records, columnMetadata } = result;
const items = [];
records.forEach((record) => {
const r = {};
let index = 0;
record.forEach((column) => {
const columnMap = column.toJSON();
for (const key in columnMap) {
const v = columnMap[key];
r[columnMetadata[index].name] = v;
}
index++;
})
items.push(r);
});
rs.push(items);
});
console.log('-- toJsonObject', rs);
return rs;
},
toJsonString(value) {
return JSON.stringify(this.toJsonObject(value));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment