@sfutureapps/db-sdk 0.3.27 → 0.3.31
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 +1 -1
- package/src/query-builder.js +18 -4
package/package.json
CHANGED
package/src/query-builder.js
CHANGED
|
@@ -24,8 +24,22 @@ export class QueryBuilder {
|
|
|
24
24
|
|
|
25
25
|
// ---- select ----
|
|
26
26
|
select(columns = "*") {
|
|
27
|
-
const
|
|
28
|
-
|
|
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,
|
|
@@ -139,7 +153,7 @@ export class QueryBuilder {
|
|
|
139
153
|
|
|
140
154
|
if (this._page != null) payload.page = this._page;
|
|
141
155
|
if (this._offset != null) payload.offset = this._offset;
|
|
142
|
-
if (this._joins.length > 0) payload.joins = this._joins;
|
|
156
|
+
if (this._joins.length > 0) payload.joins = JSON.stringify(this._joins);
|
|
143
157
|
|
|
144
158
|
const res = await post({ endpoint: "v3/api/query", data: payload });
|
|
145
159
|
|