我使用node script.js
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可以继续。我怎么能让它回来?
答案 0 :(得分:0)
要返回,您需要在完成后手动关闭连接,例如:
customlayer.sync({force: true})
.catch(err => console.log(err.message))
.finally(() => sequelize.close());