@lovrabet/sdk 1.1.20 → 1.1.21

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
@@ -354,6 +354,10 @@ import {
354
354
  type TokenResult,
355
355
  type ListResponse,
356
356
  type ListParams,
357
+ type FilterParams,
358
+ type WhereCondition,
359
+ type FieldCondition,
360
+ type ConditionOperator,
357
361
  type SortList,
358
362
  type SelectOption,
359
363
  type SelectOptionsParams,
@@ -426,10 +430,143 @@ const options = await client.models.users.getSelectOptions({
426
430
  // 返回: [{ label: '张三', value: 'user001' }, { label: '李四', value: 'user002' }]
427
431
  ```
428
432
 
433
+ ### 🔍 高级过滤查询(推荐)
434
+
435
+ `filter()` 方法提供比 `getList()` 更强大的查询能力,支持复杂的条件筛选、字段选择和排序。
436
+
437
+ #### 基础用法
438
+
439
+ ```typescript
440
+ // 简单条件查询
441
+ const result = await client.models.users.filter({
442
+ where: {
443
+ age: { $gte: 18 } // 年龄 >= 18
444
+ },
445
+ currentPage: 1,
446
+ pageSize: 20
447
+ });
448
+
449
+ console.log(result.tableData); // 数据列表
450
+ console.log(result.total); // 总数量
451
+ ```
452
+
453
+ #### 复杂条件组合
454
+
455
+ ```typescript
456
+ import { SortOrder } from "@lovrabet/sdk";
457
+
458
+ const result = await client.models.users.filter({
459
+ where: {
460
+ $and: [
461
+ // 年龄区间
462
+ { age: { $gte: 18, $lte: 45 } },
463
+ // 国家在集合内
464
+ { country: { $in: ['中国', '美国', '日本'] } },
465
+ // VIP 字段非空
466
+ { vip: { $ne: null } },
467
+ // 名称模糊匹配
468
+ { name: { $contain: 'hello' } }
469
+ ]
470
+ },
471
+ // 选择返回的字段
472
+ select: ['id', 'name', 'age', 'country', 'lastLoginAt'],
473
+ // 多字段排序:先按登录时间倒序,再按名称升序
474
+ orderBy: [
475
+ { lastLoginAt: SortOrder.DESC },
476
+ { name: SortOrder.ASC }
477
+ ],
478
+ currentPage: 1,
479
+ pageSize: 20
480
+ });
481
+ ```
482
+
483
+ #### 支持的操作符
484
+
485
+ | 操作符 | 说明 | 示例 |
486
+ |--------|------|------|
487
+ | `$eq` | 等于 | `{ status: { $eq: 'active' } }` |
488
+ | `$ne` | 不等于 | `{ status: { $ne: 'deleted' } }` |
489
+ | `$gte` / `$gteq` | 大于等于 | `{ age: { $gte: 18 } }` |
490
+ | `$lte` / `$lteq` | 小于等于 | `{ age: { $lte: 65 } }` |
491
+ | `$in` | 在集合内 | `{ country: { $in: ['中国', '美国'] } }` |
492
+ | `$contain` | 包含(模糊匹配) | `{ name: { $contain: 'test' } }` |
493
+ | `$startWith` | 以...开头 | `{ name: { $startWith: 'Mr.' } }` |
494
+ | `$endWith` | 以...结尾 | `{ email: { $endWith: '@example.com' } }` |
495
+
496
+ #### 逻辑连接符
497
+
498
+ ```typescript
499
+ // $and - 所有条件都满足
500
+ const result = await client.models.users.filter({
501
+ where: {
502
+ $and: [
503
+ { age: { $gte: 18 } },
504
+ { status: { $eq: 'active' } }
505
+ ]
506
+ }
507
+ });
508
+
509
+ // $or - 任一条件满足
510
+ const result = await client.models.users.filter({
511
+ where: {
512
+ $or: [
513
+ { country: { $eq: '中国' } },
514
+ { country: { $eq: '美国' } }
515
+ ]
516
+ }
517
+ });
518
+
519
+ // 嵌套条件
520
+ const result = await client.models.users.filter({
521
+ where: {
522
+ $and: [
523
+ { age: { $gte: 18 } },
524
+ {
525
+ $or: [
526
+ { country: { $eq: '中国' } },
527
+ { country: { $eq: '美国' } }
528
+ ]
529
+ }
530
+ ]
531
+ }
532
+ });
533
+ ```
534
+
535
+ #### 字段选择
536
+
537
+ ```typescript
538
+ // 只返回指定字段
539
+ const result = await client.models.users.filter({
540
+ select: ['id', 'name', 'email'],
541
+ currentPage: 1,
542
+ pageSize: 20
543
+ });
544
+
545
+ // 访问 JSON 字段
546
+ const result = await client.models.users.filter({
547
+ select: ['id', "value['name']", 'age'],
548
+ currentPage: 1,
549
+ pageSize: 20
550
+ });
551
+ ```
552
+
553
+ #### filter vs getList
554
+
555
+ | 特性 | `filter()` | `getList()` |
556
+ |------|-----------|------------|
557
+ | 复杂条件查询 | ✅ 支持 $and, $or 等 | ❌ 仅支持简单参数 |
558
+ | 字段选择 | ✅ 支持 select | ❌ 返回所有字段 |
559
+ | 条件操作符 | ✅ 支持 11 种操作符 | ❌ 仅支持精确匹配 |
560
+ | 排序 | ✅ 支持多字段排序 | ✅ 支持多字段排序 |
561
+ | 分页 | ✅ 支持 | ✅ 支持 |
562
+ | 性能 | 更优(减少数据传输) | 一般 |
563
+ | 使用场景 | **推荐用于复杂查询** | 简单列表查询 |
564
+
429
565
  ### ⚠️ 操作限制
430
566
 
431
567
  **OpenAPI 模式暂不支持以下操作:**
432
568
 
569
+ - ❌ `filter()` - 高级过滤查询(如需使用,请使用 WebAPI 模式)
433
570
  - ❌ `delete()` - 删除操作(如需删除,请使用 WebAPI 模式)
434
571
  - ❌ `getSelectOptions()` - 获取下拉选项(仅 WebAPI 模式支持)
435
572
 
package/dist/index.d.ts CHANGED
@@ -8,6 +8,6 @@ export { ApiNamespace } from "./src/api/index";
8
8
  export { AuthManager, } from "./src/auth/index";
9
9
  export { generateOpenApiToken, TokenGenerator, isTokenExpiring, getTokenRemainingTime, type GenerateTokenParams, type TokenResult } from "./src/auth/index";
10
10
  export type { ClientConfig, LovrabetClient, ModelConfig, ModelsConfig, } from "./src/types/index";
11
- export type { ListParams, ListResponse, Environment, BaseModelMethods, SortList, SelectOption, SelectOptionsParams, } from "./src/types/index";
11
+ export type { ListParams, ListResponse, FilterParams, WhereCondition, FieldCondition, ConditionOperator, Environment, BaseModelMethods, SortList, SelectOption, SelectOptionsParams, } from "./src/types/index";
12
12
  export type { SqlExecuteRequest, SqlExecuteResult, } from "./src/api/types";
13
13
  export { SortOrder, } from "./src/types/index";