업데이트 :비동기를 사용하는 올바른 방법, 약속에서 이중 다음()? node8, es5에 정말 바벨이 필요해?
console stringify에 대한 질문이 중복되었습니다.
이내 질문이
const genericResolver = async (table, action , values) => {
resultValues = {};
let resultValues = await models[table].findById(values.id).then(function (data) {
console.log(' ************** data');
console.log(data);
return data;
}).then(function (data2) {
console.log(' ************** data 2');
console.log(data2);
}
);
console.log('------ resultValues');
console.log(resultValues);
process.exit(1);
for data and data2 I get:
tour {
dataValues:
{ id: 'd61802ff-3eec-4a72-97ca-832f51b96bf0',
name: 'Chipre 2018',
price: '1400.00',
createdAt: 2017-09-05T04:01:27.642Z,
updatedAt: 2017-10-31T11:29:39.484Z },
_previousDataValues:
{ id: 'd61802ff-3eec-4a72-97ca-832f51b96bf0',
name: 'Chipre 2018',
price: '1400.00',
createdAt: 2017-09-05T04:01:27.642Z,
updatedAt: 2017-10-31T11:29:39.484Z },
_changed: {},
_modelOptions:
{ timestamps: true,
validate: {},
freezeTableName: true,
underscored: false,
underscoredAll: false,
paranoid: false,
rejectOnEmpty: false,
whereCollection: { id: 'd61802ff-3eec-4a72-97ca-832f51b96bf0' },
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: [],
hooks: {},
indexes: [],
name: { plural: 'tour', singular: 'tour' },
omitNull: false,
sequelize:
Sequelize {
options: [Object],
config: [Object],
dialect: [Object],
queryInterface: [Object],
models: [Object],
modelManager: [Object],
connectionManager: [Object],
importCache: {},
test: [Object] },
uniqueKeys: {} },
_options:
{ isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes:
[ 'id',
'name',
'price',
'seatsmax',
'createdAt',
'updatedAt' ] },
__eagerlyLoadedAssociations: [],
isNewRecord: false }
왜, 내가 sequelize의 ORM 통해 서 기록을 얻을 비동기 기능을 가지고있는 샘 ecode
때문에 그래서 난, 비동기와 다른 내 질문을 변경했습니다
하지만 'resultValues'내가 얻을에 대한 :
undefined
내가 바로 비동기로하고있어? 나는 node8을 사용하고 있습니다. 그래서 이론 상으로는 바벨 변환을 ES5로 변환 할 필요가 없습니까? 그냥 가져 오기 또는 내보내기? 나는 바벨 내 package.json
여기 ES6 코드를 작성하는 의심
개체, JS 참조로 전달됩니다 당신이console.log(o)
을 할 때, 당신이 콘솔에 실제 값을 볼 수 있기 때문입니다
{
"name": "myproj",
"version": "1.0.0",
"description": "GraphQL server",
"main": "server.js",
"scripts": {
"start": "nodemon ./server.js --exec babel-node -e js",
"test": "eslint . --ext .js --ext .jsx --ignore-path .gitignore --cache"
},
"author": "",
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.24.0",
"babel-eslint": "^8.0.0",
"babel-preset-es2015": "^6.24.0",
"babel-preset-stage-0": "^6.22.0",
"eslint": "^4.7.1",
"eslint-plugin-react": "^7.3.0",
"nodemon": "^1.11.0"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.17.1",
"cors": "^2.8.3",
"dotenv": "^4.0.0",
"express": "^4.15.2",
"graphql": "^0.9.1",
"graphql-server-express": "^0.6.0",
"graphql-tools": "^0.10.1",
"jsonwebtoken": "^7.2.1",
"lodash": "^4.17.4",
"passport": "^0.4.0",
"passport-jwt": "^3.0.0",
"pg": "^7.2.0",
"sequelize": "",
"validator": "^6.2.0"
}
}
가능한 중복을 [어떻게 POJO JSON.stringify 마법 작업을 계속 하시겠습니까?] (https://stackoverflow.com/questions/41747844/how-does-the-sequelize-pojo-json-stringify-magic-work) – Asthmatic