@sfutureapps/db-sdk 0.3.28 → 0.3.32

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.28",
3
+ "version": "0.3.32",
4
4
  "description": "SfutureApps JS SDK for ThinkPHP DB Gateway (MySQL)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,8 +24,22 @@ export class QueryBuilder {
24
24
 
25
25
  // ---- select ----
26
26
  select(columns = "*") {
27
- const cols = String(columns).trim();
28
- this._select = cols === "*" || cols === "" ? [ "*" ] : cols.split(",").map(s => s.trim()).filter(Boolean);
27
+ const list = Array.isArray(columns) ? columns : String(columns).split(",");
28
+ const next = list.map(s => String(s).trim()).filter(Boolean);
29
+
30
+ if (next.length === 0 || next.includes("*")) {
31
+ this._select = [ "*" ];
32
+ return this;
33
+ }
34
+
35
+ if (this._select.length === 1 && this._select[ 0 ] === "*") {
36
+ this._select = next;
37
+ return this;
38
+ }
39
+
40
+ const set = new Set(this._select);
41
+ for (const col of next) set.add(col);
42
+ this._select = Array.from(set);
29
43
  return this;
30
44
  }
31
45
 
@@ -125,7 +139,7 @@ export class QueryBuilder {
125
139
  async execute() {
126
140
  const payload = {
127
141
  table: this.tableName,
128
- select: this._select,
142
+ select: this._select.join(","),
129
143
  filters: JSON.stringify(this._filters),
130
144
 
131
145
  order: this._order,
@@ -186,7 +200,7 @@ export class QueryBuilder {
186
200
  }
187
201
  return post({
188
202
  endpoint: "v3/api/update",
189
- data: { table: this.tableName, values, filters: this._filters }
203
+ data: { table: this.tableName, values, filters: JSON.stringify(this._filters) }
190
204
  });
191
205
  }
192
206
 
@@ -196,7 +210,7 @@ export class QueryBuilder {
196
210
  }
197
211
  return post({
198
212
  endpoint: "v3/api/delete",
199
- data: { table: this.tableName, filters: this._filters }
213
+ data: { table: this.tableName, filters: JSON.stringify(this._filters) }
200
214
  });
201
215
  }
202
216
  }