小编aug*_*ral的帖子

尝试请求存储库时,TypeORM 未找到连接“默认”

我正在使用 Express+TypeORM 构建一个 API。这是我的 ormconfig.json:

{
  "type": "postgres",
  "host": "localhost",
  "port": "5432",
  "username": "mdsp9070",
  "password": "mdsp9070",
  "database": "mesha",
  "entities": ["./src/entities/*.ts"],
  "migrations": ["./src/shared/infra/typeorm/migrations/*.ts"],
  "cli": {
    "migrationsDir": "./src/shared/infra/typeorm/migrations"
  }
}
Run Code Online (Sandbox Code Playgroud)

我的实体定义为:

{
  "type": "postgres",
  "host": "localhost",
  "port": "5432",
  "username": "mdsp9070",
  "password": "mdsp9070",
  "database": "mesha",
  "entities": ["./src/entities/*.ts"],
  "migrations": ["./src/shared/infra/typeorm/migrations/*.ts"],
  "cli": {
    "migrationsDir": "./src/shared/infra/typeorm/migrations"
  }
}
Run Code Online (Sandbox Code Playgroud)

在我的 CreateUserUseCase 中,我将此存储库称为:

import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
} from "typeorm";

@Entity("users")
export class User {
  @PrimaryGeneratedColumn("uuid")
  id: string;

  @Column()
  name: string;

  @Column()
  email: string;

  @Column()
  birthYear: string; …
Run Code Online (Sandbox Code Playgroud)

orm node.js express typescript typeorm

5
推荐指数
1
解决办法
9158
查看次数

标签 统计

express ×1

node.js ×1

orm ×1

typeorm ×1

typescript ×1