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 build
和npm run fixtures
。
启动步骤
-
启动 PostgreSQL 数据库:
docker-compose -f docker-compose-postgres.yml up --build
-
构建项目:
npm run build
-
加载 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 项目。