befly 3.9.6 → 3.9.7

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/types/common.d.ts CHANGED
@@ -92,6 +92,19 @@ export type ComparisonOperator = '=' | '>' | '<' | '>=' | '<=' | '!=' | '<>' | '
92
92
  */
93
93
  export type JoinType = 'INNER' | 'LEFT' | 'RIGHT' | 'FULL';
94
94
 
95
+ /**
96
+ * JOIN 选项
97
+ * 用于简化多表联查的写法
98
+ */
99
+ export interface JoinOption {
100
+ /** JOIN 类型,默认 'left' */
101
+ type?: 'left' | 'right' | 'inner';
102
+ /** 要联接的表名(不支持别名) */
103
+ table: string;
104
+ /** JOIN 条件(如 'order.user_id = user.id') */
105
+ on: string;
106
+ }
107
+
95
108
  /**
96
109
  * 工具函数返回类型
97
110
  */
@@ -4,6 +4,7 @@
4
4
 
5
5
  import type { SqlValue } from 'befly-shared/types';
6
6
  import type { DatabaseTables, TableName, TableType, TableInsertType, TableUpdateType, TypedWhereConditions } from './table';
7
+ import type { JoinOption } from './common';
7
8
 
8
9
  // 重新导出表类型工具
9
10
  export type { DatabaseTables, TableName, TableType, TableInsertType, TableUpdateType, SystemFields, BaseTable, InsertType, UpdateType, SelectType, TypedWhereConditions } from './table';
@@ -98,12 +99,14 @@ export interface TypedDeleteOptions<K extends TableName> {
98
99
  * 查询选项(兼容旧版,不进行类型检查)
99
100
  */
100
101
  export interface QueryOptions {
101
- /** 表名 */
102
+ /** 表名(可带别名,如 'order o') */
102
103
  table: string;
103
- /** 查询字段 */
104
+ /** 查询字段(联查时需带表别名,如 'o.id', 'u.username') */
104
105
  fields?: string[];
105
- /** WHERE 条件 */
106
+ /** WHERE 条件(联查时字段需带表别名,如 { 'o.state': 1 }) */
106
107
  where?: WhereConditions;
108
+ /** 多表联查选项 */
109
+ joins?: JoinOption[];
107
110
  /** 排序(格式:["字段#ASC", "字段#DESC"]) */
108
111
  orderBy?: string[];
109
112
  /** 页码(从 1 开始) */