【问题标题】:TypeOrm Entity and ormconfigsTypeOrm 实体和 ormconfigs
【发布时间】:2021-12-14 04:53:33
【问题描述】:

您好,我对 typem ormconfig 有疑问 我有一个包含以下内容的 dockerfile 设置:

#building code
FROM node as builder
WORKDIR usr/app
COPY package*.json ./
RUN yarn install
COPY . .
RUN yarn run build

#stage 2
FROM node
WORKDIR usr/app
COPY package*.json ./
RUN yarn install --production

COPY --from=builder /usr/app/dist ./dist

COPY ormconfig.json .
COPY .env . 

expose 4000
CMD node dist/src/index.js

我的 orm 配置是这样的:

{
  "type": "postgres",
  "host": "db",
  "port": 5432,
  "username": "spirit",
  "password": "emasa",
  "database": "emasa_base",
  "synchronize": true,
  "logging": false,
  "entities": ["src/entity/**/*.ts"],
  "migrations": ["src/migration/**/*.ts"],
  "subscribers": ["src/subscriber/**/*.ts"],
  "cli": {
    "entitiesDir": "src/entity",
    "migrationsDir": "src/migration",
    "subscribersDir": "src/subscriber"
  }
}

但是由于我使用打字稿并使用 docker 来运行我的节点,我怀疑我应该放入什么:

"entities": ["src / entity / ** / *. ts"],
      "migrations": ["src / migration / ** / *. ts"],
      "subscribers": ["src / subscriber / ** / *. ts"]

src 还是 dist?

目前src在启动服务器时没有在数据库中创建我的表我不知道为什么

【问题讨论】:

    标签: typescript typeorm


    【解决方案1】:

    当你将ts代码编译成js时,文件扩展名将从.ts更改为.js,那么你必须更改你的ormconfig

    例子:

    "entities": ["src/entity/**/*.ts"],
    

    "entities": ["src/entity/**/*.js"], // Or dist/src/entity/**/*.js
    

    【讨论】:

      【解决方案2】:

      这种方式更通用,你可以用两个扩展来引用它:

      "entities": [`src/entity/**/*{.ts,.js}`]
      

      【讨论】:

        猜你喜欢
        • 2018-09-10
        • 2018-09-24
        • 2020-12-11
        • 2020-09-18
        • 1970-01-01
        • 2022-11-11
        • 2019-11-13
        • 2021-05-23
        • 2020-05-06
        相关资源
        最近更新 更多