我正在设计Moleculer JS微服务,它扩展了Moleculer DB并且可以扩展SQL(例如Sequelize)和noSQL(例如MongoDB)适配器。
这是book
服务架构
const uuid = require('uuid/v4')
const Sequelize = require('sequelize')
const DBService = require('moleculer-db')
const pkg = require('../package.json')
const adapter = require('../db/sql.adapter')
module.exports = {
name: 'book',
version: pkg.version,
mixins: [DBService],
settings: {
$noVersionPrefix: true,
idField: 'id',
},
adapter,
model: {
name: 'book',
define: {
id: { type: Sequelize.UUID, primaryKey: true, allowNull: false, defaultValue: uuid },
name: { type: Sequelize.STRING, allowNull: false },
},
},
}
尽管将在启动book
表/集合的Molecularr服务上创建模型名称为books
(无论是SQL还是noSQL都无关紧要)。没关系。
但是,如果我要创建另一个将保留已删除项目的服务,则将分别创建books_archive
或book_archive
-books_archives
或book_archives
。 / p>
freezeTableName: true,
tableName: 'booksArchive',
配置属性,我尝试将其放在模式的settings
块中和model
块中,以及在适配器构造属性中(请参见下文),但是没有运气-仍然创建了collection(table)仅包含一个额外的s
字符。有什么解决办法吗?
const adapter = new SQLAdapter(config.get('database.pg.uri'), {
dialect: 'postgres',
logging: false,
freezeTableName: true,
tableName: 'booksArchive',
})
答案 0 :(得分:0)
基于序列化文档,应在“模型”选项中进行设置。试试吧:
module.exports = {
name: 'book',
version: pkg.version,
mixins: [DBService],
settings: {
$noVersionPrefix: true,
idField: 'id',
},
adapter,
model: {
name: 'book',
define: {
id: { type: Sequelize.UUID, primaryKey: true, allowNull: false, defaultValue: uuid },
name: { type: Sequelize.STRING, allowNull: false },
},
options: {
freezeTableName: true,
tableName: 'booksArchive',
}
},
}