nodejs项目,新建表步骤

一  生成文件

plopfile.js 定义如下

  plop.setGenerator('api', {
    description: 'Create a new components.',
    prompts: [
      {
        type: 'input',
        name: 'name',
        message: 'name of the components'
      },
      {
        type: 'input',
        name: 'description',
        message: 'description of the components'
      }
    ],

执行命令  npm run plop api  drillplan  演练计划

其中

api 为生成器的名称

drillplan  模块名称,后面+s就是表的名称 ,也就是drillplans  

演练计划  模块说明.也就是表的中文名称

然后会按照对应模板生成文件,

 二修改 model.ts

将 定义好的 表信息拷贝到注释中 例如

/*

doc_code  VARCHAR(100)  文档编号  如CMNX-ZWDCA4-EOP-DQ-ZPXT-01
下面可以是所有的字段定义

*/

再下面按 tab键,会自动生成字段定义

@Column({ comment: "文档编号", nullable: true })
  public doc_code: string;
三 生成建表脚本
 npm run sql 演练计划
会在 migrations文件夹生成一个文件 1784271036488-演练计划.ts
打开后,会有一堆sql,
直接拷贝up中的 CREATE TABLE `drillplans... 到 导航猫 执行即可
posted @ 2026-07-17 14:38  simadi  阅读(4)  评论(0)    收藏  举报