【发布时间】:2019-10-06 22:04:19
【问题描述】:
我正在设计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 上的分子服务开始 books 将创建表/集合(不管是 SQL 还是 noSQL 之一)。没关系。
但如果我想创建另一个服务来保留已删除的项目,例如 books_archive 或 book_archive - books_archives 或 book_archives(分别)将被创建。
续集documentation包含
freezeTableName: true,
tableName: 'booksArchive',
配置属性,我试图将其放入架构的 settings 块和 model 块内,以及适配器构造属性(见下文)但没有运气 - 创建的集合(表)仍然只包含一个额外的s 字符。有什么解决办法吗?
const adapter = new SQLAdapter(config.get('database.pg.uri'), {
dialect: 'postgres',
logging: false,
freezeTableName: true,
tableName: 'booksArchive',
})
【问题讨论】:
-
这个答案在 Sequelize 适配器 stackoverflow.com/a/34558832/1902296 的上下文中对我很有用
标签: moleculer