@sfutureapps/db-sdk 0.3.26 → 0.3.27

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfutureapps/db-sdk",
3
- "version": "0.3.26",
3
+ "version": "0.3.27",
4
4
  "description": "SfutureApps JS SDK for ThinkPHP DB Gateway (MySQL)",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.d.ts CHANGED
@@ -25,6 +25,8 @@ export type OrderOptions = {
25
25
  ascending?: boolean;
26
26
  };
27
27
 
28
+ export type JoinType = "INNER" | "LEFT" | "RIGHT" | "FULL" | "CROSS" | (string & {});
29
+
28
30
  export class QueryBuilder<T = any, TSingle extends boolean = false> {
29
31
  constructor(table: string);
30
32
 
@@ -79,6 +81,9 @@ export class QueryBuilder<T = any, TSingle extends boolean = false> {
79
81
  havingLt(col: keyof T | string, val: any): QueryBuilder<T, TSingle>;
80
82
  havingNeq(col: keyof T | string, val: any): QueryBuilder<T, TSingle>;
81
83
 
84
+ // ---- join ----
85
+ join(table: string, on: string, type?: JoinType): QueryBuilder<T, TSingle>;
86
+
82
87
  // ---- execute ----
83
88
  execute(): Promise<QueryResponse<TSingle extends true ? T | null : T[]>>;
84
89
 
@@ -1,4 +1,4 @@
1
- import post from "./client";
1
+ import post from "./client.js";
2
2
 
3
3
  export class QueryBuilder {
4
4
  constructor(table) {
@@ -18,6 +18,8 @@ export class QueryBuilder {
18
18
  this._distinct = false;
19
19
  this._group = [];
20
20
  this._having = [];
21
+
22
+ this._joins = [];
21
23
  }
22
24
 
23
25
  // ---- select ----
@@ -108,12 +110,24 @@ export class QueryBuilder {
108
110
  havingLt(col, val) { this._having.push({ col, op: "lt", val }); return this; }
109
111
  havingNeq(col, val) { this._having.push({ col, op: "neq", val }); return this; }
110
112
 
113
+ // ---- join ----
114
+ join(table, on, type = "INNER") {
115
+ const joinTable = String(table ?? "").trim();
116
+ const joinOn = String(on ?? "").trim();
117
+ if (!joinTable || !joinOn) return this;
118
+
119
+ const joinType = String(type ?? "INNER").trim().toUpperCase();
120
+ this._joins.push({ table: joinTable, on: joinOn, type: joinType });
121
+ return this;
122
+ }
123
+
111
124
  // ---- execute ----
112
125
  async execute() {
113
126
  const payload = {
114
127
  table: this.tableName,
115
128
  select: this._select,
116
129
  filters: JSON.stringify(this._filters),
130
+
117
131
  order: this._order,
118
132
  limit: this._limit ?? 20,
119
133
  count: this._withCount,
@@ -125,6 +139,7 @@ export class QueryBuilder {
125
139
 
126
140
  if (this._page != null) payload.page = this._page;
127
141
  if (this._offset != null) payload.offset = this._offset;
142
+ if (this._joins.length > 0) payload.joins = this._joins;
128
143
 
129
144
  const res = await post({ endpoint: "v3/api/query", data: payload });
130
145