nicot 1.1.38 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -208,18 +208,23 @@ NICOT 提供了一套查询装饰器,用于在 Entity 字段上声明支持的
208
208
 
209
209
  ### ✅ 内建查询装饰器
210
210
 
211
- | 装饰器名 | 查询效果 |
212
- |-------------------------------|------------------------------------------|
213
- | `@QueryEqual()` | 精确匹配:`WHERE field = :value` |
214
- | `@QueryLike()` | 前缀模糊匹配:`WHERE field LIKE :value%` |
215
- | `@QuerySearch()` | 宽泛模糊搜索:`WHERE field LIKE %:value%` |
216
- | `@QueryMatchBoolean()` | `true/false/1/0` 转换为布尔类型查询 |
217
- | `@QueryEqualZeroNullable()` | `0 → IS NULL`,否则 `= :value`(适合 nullable) |
218
- | `@QueryGreater(field)` | 大于查询:`WHERE field > :value` |
219
- | `@QueryLess(field)` | 小于查询:`WHERE field < :value` |
220
- | `@QueryGreaterOrEqual(field)` | 大于等于查询:`WHERE field >= :value` |
221
- | `@QueryLessOrEqual(field)` | 小于等于查询:`WHERE field <= :value` |
222
- | `@QueryFullText(options)` | 全文搜索查询,只支持 PostgreSQL,会自动建索引 |
211
+ | 装饰器名 | 查询效果 |
212
+ |------------------------------------------------------|-------------------------------------------------|
213
+ | `@QueryEqual()` | 精确匹配:`WHERE field = :value` |
214
+ | `@QueryLike()` | 前缀模糊匹配:`WHERE field LIKE :value%` |
215
+ | `@QuerySearch()` | 宽泛模糊搜索:`WHERE field LIKE %:value%` |
216
+ | `@QueryMatchBoolean()` | `true/false/1/0` 转换为布尔类型查询 |
217
+ | `@QueryEqualZeroNullable()` | `0 → IS NULL`,否则 `= :value`(适合 nullable) |
218
+ | `@QueryIn()` | 包含查询:`WHERE field IN (:...value)`,value 可以数组或者逗号分隔 |
219
+ | `@QueryNotIn()` | 不包含查询:`WHERE field NOT IN (:...value)` |
220
+ | `@QueryGreater(field)` | 大于查询:`WHERE field > :value` |
221
+ | `@QueryLess(field)` | 小于查询:`WHERE field < :value` |
222
+ | `@QueryGreaterOrEqual(field)` | 大于等于查询:`WHERE field >= :value` |
223
+ | `@QueryLessOrEqual(field)` | 小于等于查询:`WHERE field <= :value` |
224
+ | `@QueryJsonbHas()` | JSONB 包含键查询:`WHERE field ? :value` |
225
+ | `@QueryOperator('=')` | 自定义操作符查询:`WHERE field <operator> :value` |
226
+ | `@QueryWrap((entExpr, valExpr) => `${entExpr} = ${valExpr}`) | 自定义查询片段 |
227
+ | `@QueryFullText(options)` | 全文搜索查询,只支持 PostgreSQL,会自动建索引 |
223
228
 
224
229
  ---
225
230
 
@@ -304,6 +309,35 @@ viewsOrderBy?: 'ASC' | 'DESC';
304
309
 
305
310
  ---
306
311
 
312
+ ## GetMutator
313
+
314
+ GET 方法的参数只能是 URL 参数,因此数据类型只能是 string,具有局限性。
315
+
316
+ NICOT 提供了 `GetMutator` 装饰器,允许你在实体字段上定义一个转换函数,将 URL 参数转换为正确的数据类型,并把 OpenAPI 文档中 GET 接口的数据类型改为目标类型。
317
+
318
+ ### 示例
319
+
320
+ ```ts
321
+ @JsonColumn(SomeObject)
322
+ @GetMutator((val: string) => JSON.parse(val)) // GET 参数不会体现为 SomeObject,而是 string
323
+ @QueryOperator('@>') // JSONB 包含查询
324
+ meta: SomeObject;
325
+ ```
326
+
327
+ ### 内建 GetMutator
328
+
329
+ - `@GetMutatorBool()`
330
+ - `@GetMutatorInt()`
331
+ - `@GetMutatorFloat()`
332
+ - `@GetMutatorStringSeparated(',')`
333
+ - `@GetMutatorIntSeparated()`
334
+ - `@GetMutatorFloatSeparated()`
335
+ - `@GetMutatorJson()`
336
+
337
+ > `@BoolColumn()` 已经内建了 `@GetMutatorBool()`
338
+
339
+ ---
340
+
307
341
  ## 🧩 实体关系示例
308
342
 
309
343
  ```ts