【发布时间】:2019-02-16 20:57:25
【问题描述】:
我想将 Node.js 与 Sequelize 和 SQLite 一起使用。我有以下用户模型:
const User = sequelize.define('user', {
rowid: {
type: 'INTEGER',
primaryKey: true,
},
// other properties
});
如果我现在执行const newUser = await User.create({ /* properties */ }),我希望能够使用newUser.rowid 访问新用户的ID。但事实并非如此,除非我将autoIncrement: true 添加到规范中。关注https://www.sqlite.org/autoinc.html,我不想这样做。还有其他可能吗?
编辑
事实证明,这只有通过创建没有autoIncrement: true 的表才能实现,然后才将其添加到列定义中。更实用的方法可能是只使用自动增量,对于大多数小型应用程序来说,性能下降并不重要。
【问题讨论】:
标签: node.js sqlite sequelize.js