gpt4 book ai didi

postgresql - Sequelizejs 模式同步不返回

转载 作者:行者123 更新时间:2023-12-03 22:41:09 25 4
gpt4 key购买 nike

我用 node script.js 运行这个 sequelize 代码

const Sequelize = require('./node_modules/sequelize')
const sequelize = new Sequelize('postgres://user:pw@localhost:5432/db')

const customlayer = sequelize.define('customlayer', {
ogc_fid: {
type: Sequelize.INTEGER,
autoIncrement: true,
field: 'ogc_fid',
validate: {isInt: true},
primaryKey: true
},
wkb_geometry: {
type: Sequelize.GEOMETRY('POINT'),
field: 'wkb_geometry',
allowNull: false
},
createdAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW
},
updatedAt: {
type: Sequelize.DATE,
allowNull: true
}
})

customlayer.sync({force: true}).catch(err => console.log(err.message))

它有效(日志输出中没有错误,并且在 Postgres 中创建了表)但它不会返回到正常的终端提示......,所以我必须按 Ctrl+C 才能在终端中继续。由于我将此用作 Ansible 脚本的一部分,因此我需要编写脚本以返回,以便 Ansible 可以继续。我怎样才能让它回来?

最佳答案

要返回,您需要在完成后手动关闭连接,例如:

customlayer.sync({force: true})
.catch(err => console.log(err.message))
.finally(() => sequelize.close());

关于postgresql - Sequelizejs 模式同步不返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45103487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com