The process to generate tables with changing names in Sequelize and TypeScript is as follows:
interface TableName {
tableName: string;
// define other table properties
}
const Model = sequelize.define<TableName, {}>(
'tableName',
{// define table schema
});
Model.findAll({
where: {
// define query criteria
},
table: 'tableName'
})
const result = await Model.findAll({
where: {
// define query criteria
},
table: 'tableName'
});
Note that when using the Sequelize CLI to generate migrations, you can also pass a custom table name as a parameter.
npx sequelize-cli migration:generate --name create-customnamedTable --tableName customnamedTable
Asked: 2022-12-30 11:00:00 +0000
Seen: 9 times
Last updated: Mar 12 '23