AKTUALISIERT:richtigen Weg mit async, double dann() in Versprechen? node8, muss wirklich zu es5 babel?
die Frage über Konsole stringify ist dupliziert; so habe ich meine Frage zu einem anderen mit Asynchron geändert, weil die ecode sam ist
ich eine Asynchron-Funktion, die einen Datensatz throug sequelize ORM bekommen, warum
Meine Frage ist
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 }
aber für 'resultValues' ich:
undefined
ich rechts mit Asynchron tun? Ich benutze node8, also brauche ich in der Theorie nicht alles in ES5 konvertieren? einfach importieren oder exportieren? Ich vermute, dass babel schafft ES6 Code
Hier mein package.json
{
"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"
}
}
Mögliche Duplikat [How macht die Sequelize POJO JSON.Stringify magische Arbeit?] (https://StackOverflow.com/questions/41747844/how-does-the-sequelize-pojo-json-stringify-magic-work) – Asthmatic