packages/typeorm/SKILL.md
@hile/typeorm 的代码生成与使用规范。适用于 DataSource 服务加载、transaction 事务封装、及与 @hile/core/@hile/cli 集成场景。
npx skillsauth add cevio/hile hile-typeormInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
本文档规范 @hile/typeorm 的使用方式,确保 DataSource 生命周期与事务行为一致。
@hile/typeorm 提供:
DataSource(服务 key 为稳定 symbol,见包内实现)transaction:事务封装,支持失败时 LIFO 执行补偿回调依赖:@hile/core、typeorm。
| 变量 | 说明 |
|---|---|
| TYPEORM_TYPE | 数据库类型 |
| TYPEORM_HOST | 主机 |
| TYPEORM_USERNAME | 用户名 |
| TYPEORM_PASSWORD | 密码 |
| TYPEORM_DATABASE | 数据库名 |
| TYPEORM_PORT | 端口(字符串转数字) |
| TYPEORM_CHARSET | 字符集 |
| TYPEORM_ENTITY_PREFIX | 表名前缀 |
| TYPEORM_ENTITIES | 实体目录(单一路径) |
| TYPEORM_SYNCHRONIZE | 设为 true 时开启 TypeORM synchronize(自动改表结构);未设或其他值则为关闭 |
行为:
synchronize:TYPEORM_SYNCHRONIZE === 'true' 时为 true,否则为 falseNODE_ENV === 'development' 时 logging: trueTYPEORM_ENTITIES 时实体为空数组import { loadService } from '@hile/core'
import typeormService from '@hile/typeorm'
const ds = await loadService(typeormService)
import { transaction } from '@hile/typeorm'
const result = await transaction(ds, async (runner, rollback) => {
rollback(async () => {
// 事务失败时执行的补偿逻辑
})
// 使用 runner 执行写操作
return value
})
loadService(typeormService) 获取 DataSource。rollback(fn) 注册,不在事务外分散处理。loadService,不要模块顶层缓存。| 导出 | 说明 |
|---|---|
| 默认导出 | Hile 服务化 DataSource |
| transaction(datasource, callback) | 事务封装,失败时执行 rollback 队列 |
devops
@hile/model: defineModel/loadModel 定义和消费模型;services 依赖注入;pipeline 中间件链;每次 loadModel 重新执行 main
development
Code generation and contribution rules for @hile/micro-dynamic-configs. Use when editing this package or when the user asks about dynamic config patterns or API.
development
Code generation and contribution rules for @hile/cache. Use when editing this package or when the user asks about @hile/cache API, types, patterns, or features.
development
Code generation and contribution rules for @hile/micro. Use when editing this package or when the user asks about @hile/micro API, types, patterns, or features.