TypeORM Fixtures 项目教程

TypeORM Fixtures 项目教程

typeorm-fixtures:pill: Fixtures loader for typeorm 🇺🇦项目地址:https://gitcode.com/gh_mirrors/ty/typeorm-fixtures

1. 项目的目录结构及介绍

typeorm-fixtures/
├── docker-compose-postgres.yml
├── entity/
│   └── ...
├── fixtures/
│   └── ...
├── fixtures-processor/
│   └── ...
├── .editorconfig
├── .gitignore
├── .nvmrc
├── README.md
├── ormconfig.yml
├── package.json
├── tsconfig.json
└── yarn.lock

目录结构介绍

  • docker-compose-postgres.yml: Docker 配置文件,用于启动 PostgreSQL 数据库。
  • entity/: 存放 TypeORM 实体文件的目录。
  • fixtures/: 存放测试数据(fixtures)的目录。
  • fixtures-processor/: 处理 fixtures 的目录。
  • .editorconfig: 编辑器配置文件。
  • .gitignore: Git 忽略文件配置。
  • .nvmrc: Node.js 版本管理配置文件。
  • README.md: 项目说明文档。
  • ormconfig.yml: TypeORM 配置文件。
  • package.json: 项目依赖和脚本配置文件。
  • tsconfig.json: TypeScript 配置文件。
  • yarn.lock: Yarn 包管理器锁文件。

2. 项目的启动文件介绍

启动文件

  • docker-compose-postgres.yml: 用于启动 PostgreSQL 数据库的 Docker 配置文件。
  • package.json: 包含项目的启动脚本,如 npm run buildnpm run fixtures

启动步骤

  1. 启动 PostgreSQL 数据库:

    docker-compose -f docker-compose-postgres.yml up --build
    
  2. 构建项目:

    npm run build
    
  3. 加载 fixtures:

    npm run fixtures
    

3. 项目的配置文件介绍

ormconfig.yml

ormconfig.yml 是 TypeORM 的配置文件,用于配置数据库连接、实体路径等信息。

# ormconfig.yml 示例
default:
  type: "postgres"
  host: "localhost"
  port: 5432
  username: "test"
  password: "test"
  database: "test"
  synchronize: true
  logging: false
  entities:
    - "entity/**/*.ts"
  migrations:
    - "migration/**/*.ts"
  subscribers:
    - "subscriber/**/*.ts"

package.json

package.json 包含项目的依赖和脚本配置。

{
  "name": "typeorm-fixtures",
  "version": "1.0.0",
  "scripts": {
    "build": "tsc",
    "fixtures": "typeorm-fixtures-cli"
  },
  "dependencies": {
    "typeorm": "^0.2.37"
  },
  "devDependencies": {
    "typeorm-fixtures-cli": "^1.0.0"
  }
}

tsconfig.json

tsconfig.json 是 TypeScript 的配置文件,用于配置 TypeScript 编译选项。

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true
  }
}

通过以上配置文件和启动步骤,您可以顺利地启动和配置 TypeORM Fixtures 项目。

typeorm-fixtures:pill: Fixtures loader for typeorm 🇺🇦项目地址:https://gitcode.com/gh_mirrors/ty/typeorm-fixtures

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

万蝶娴Harley

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值