我在用nodejs
这是我的名为createSchema的函数:
const createSchema = () => {
Business.findAll({
raw: true,
}).then((data) => {
data.forEach((client) => {
postgresDB.createSchema(client.code).then(() => {
Object.keys(postgresDB.models).forEach((currentItem) => {
postgresDB.models[currentItem].schema(client.code).sync();
});
console.log('Postgres schema created');
}).catch(() => {
});
});
}).catch((err) => {
console.log('Warning:', err.message);
});
};
createSchema();
我在这个post函数中调用这个函数
exports.createBusiness = (req, res) => {
const business = {
name: req.body.name,
code: req.body.code,
email: req.body.email,
};
Business.create(business)
.then((rawbusinessData) => {
createSchema() // this is the function
.then(() => { . // i want to complete createSchema fully then only i want to execute this below stuffs
const businessData = rawbusinessData.get({ plain: true });
const loginDetails = {
username: 'sameer',
password: encrypt('sameer'),
};
const schemaLogin = postgresDB.models.login.schema(businessData.code);
schemaLogin.create(loginDetails).then((loginData) => {
console.log('loginData:', loginData);
});
res.status(200).send(businessData);
});
})
.catch((err) => {
console.log('err:', err);
});
};
我正在调用第二个post函数中的第一个函数
创建业务
,
我想完全完成createSchema函数,然后只需要执行其他
然后
第二个函数中的方法()被调用
创建业务
看到我的代码,我做了一个需要首先工作的评论,
我尝试了异步等待,但没有工作!