I'm designing Moleculer JS microservice which extends Moleculer DB and can extend both SQL (for example Sequelize) and noSQL (for instance, MongoDB) adapters.
Here is a book
service schema
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 },
},
},
}
Though model name is book
on moleculer service starting books
table/collection will be created (it doesn't matter whether it is SQL or noSQL one). That is OK.
But in case I want to create another service which would keep deleted items, say books_archive
or book_archive
- books_archives
or book_archives
(respectively) will be created.
Sequelize documentation contains
freezeTableName: true,
tableName: 'booksArchive',
configuration properties, which I tried to put in settings
block of the schema and inside model
block, and inside adapter construction properties (see below) but with no luck - collection(table) created still just contains an extra s
character. Is there any solution?
const adapter = new SQLAdapter(config.get('database.pg.uri'), {
dialect: 'postgres',
logging: false,
freezeTableName: true,
tableName: 'booksArchive',
})