From 2fcc7cdb3977382f815ac783da8440e28f23640a Mon Sep 17 00:00:00 2001 From: xiaopeng Date: Sun, 9 Feb 2025 22:10:57 +0800 Subject: [PATCH] add cursor rules --- .cursor/rules/controller.mdc | 2 +- .cursor/rules/db.mdc | 2 +- .cursor/rules/module.mdc | 19 ++++++++++++++++++- .cursorrules | 15 +++++++++++++-- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.cursor/rules/controller.mdc b/.cursor/rules/controller.mdc index 9df4dfc..483c1cc 100644 --- a/.cursor/rules/controller.mdc +++ b/.cursor/rules/controller.mdc @@ -161,7 +161,7 @@ export class AppDemoGoodsController extends BaseController { | 参数 | 类型 | 说明 | | --------- | ------ | ------------------------------------------------------------------ | -| entity | Class | 实体类 | +| entity | Class | 实体类,注意不能写表名 | | alias | String | 别名,如果有关联表默认主表的别名为`a`, 其他表一般按 b、c、d...设置 | | condition | String | 关联条件 | | type | String | 内关联: 'innerJoin', 左关联:'leftJoin' | diff --git a/.cursor/rules/db.mdc b/.cursor/rules/db.mdc index 4a8923d..d9aaab4 100644 --- a/.cursor/rules/db.mdc +++ b/.cursor/rules/db.mdc @@ -8,7 +8,7 @@ globs: 中文文档:](httpsom) -官方文档:[https://typeorm.io](https:/据库文档:[https://www.midwayjs.org/docs/extensions/orm](https://www.midwayjs.org/docs/extensions/orm) +官方文档:[https://typeorm.io](mdc:https:/据库文档:[https:/www.midwayjs.org/docs/extensions/orm](https:/www.midwayjs.org/docs/extensions/orm) ## 数据库配置 diff --git a/.cursor/rules/module.mdc b/.cursor/rules/module.mdc index 8c01f72..371f776 100644 --- a/.cursor/rules/module.mdc +++ b/.cursor/rules/module.mdc @@ -11,7 +11,7 @@ globs: ```ts ├── modules │ └── base(基础的权限管理系统) - │ │ └── controller(api接口, 用法参考 [controller.mdc](mdc:.cursor/rules/controller.mdc) ) + │ │ └── controller(api接口, 用法参考 [controller.mdc](mdc:.cursor/rules/controller.mdc) ,必要时需要创建关联查询, 配置pageQueryOp) │ │ │ └── admin(后台管理接口) │ │ │ └── app(应用接口,如小程序APP等) │ │ └── dto(可选,参数校验) @@ -25,6 +25,23 @@ globs: ``` +创建模块一般需要创建`controller`、`entity`、`service`, +如果entity文件夹没有子文件夹,那么引用BaseEntity是 + + - 引用BaseEntity固定为 + + ```ts +import { BaseEntity } from '../../modules/base/entity/base'; + ``` + + 错误示例 + + ```ts +import { BaseEntity } from '../../../modules/base/entity/base'; + ``` + + 多了一个层级 + ## 模块配置 #### config.ts diff --git a/.cursorrules b/.cursorrules index 5f0e4e5..736409e 100644 --- a/.cursorrules +++ b/.cursorrules @@ -1,5 +1,5 @@ # 项目背景 -- 数据库:MySQL、Sqlite、Postgres、Typeorm(0.3.20) +- 数据库:MySQL、Sqlite、Postgres、Typeorm(0.3.20版本, 不使用外键方式,如@ManyToOne、@OneToMany等) - 语言:TypeScript、JavaScript、CommonJS - 框架:Koa.js、midway.js、cool-admin-midway - 项目版本:8.x @@ -37,4 +37,15 @@ # 其它 - - 始终使用中文回复,包括代码注释等 \ No newline at end of file + - 始终使用中文回复,包括代码注释等 + - `@midwayjs/decorator`,已弃用,使用`@midwayjs/core` + - 不要使用自定义sql来操作数据库,而是使用typeorm的api,统计相关的可以考虑使用原生sql + - Controller中不允许重写`add`、`delete`、`update`、`info`、`list`、`page`方法 + - Controller的关联查询一般写在pageQueryOp中,必要时需要创建关联查询 + - Entity字段使用驼峰命名,如:studentNo + - Entity不允许使用@ManyToOne、@OneToMany等外键关系 + - Entity的BaseEntity引用固定为:`import { BaseEntity } from '../../base/entity/base';`,禁止修改层级 + - 创建api接口时,不要多层级如:`/student/detail`,改为`/studentDetail`,用驼峰法; + - 本项目是版本8.x,所有代码都需要按照新的写法进行编写,如Entity字典的配置 + - 文件的命名不要使用驼峰法,而是使用下划线法,如:student_info.entity.ts,另外禁止太啰嗦,比如:student模块下的学生信息,不要写成:student_info, 而是写成info.ts,班级信息:class.ts,不要写成student_class.ts + \ No newline at end of file