@xuda.io/xuda-dbs-plugin-xuda 1.0.51 → 1.0.52
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/server.js +40 -1
package/package.json
CHANGED
package/server.js
CHANGED
@@ -839,8 +839,22 @@ const query_db = async function (e, db, app_id_reference, table_obj) {
|
|
839
839
|
try {
|
840
840
|
const body = await db.view(`xuda`, view, opt);
|
841
841
|
if (e.reduce) {
|
842
|
-
|
842
|
+
let rows = [];
|
843
|
+
|
844
|
+
$.each(data.rows, (key, val) => {
|
845
|
+
const arr = val.key[2];
|
846
|
+
console.log(arr);
|
847
|
+
var obj = {};
|
848
|
+
$.each(arr, (arr_key, arr_val) => {
|
849
|
+
obj[sort[arr_key]] = arr_val; //val.value;
|
850
|
+
});
|
851
|
+
obj["REDUCE_VALUE"] = val.value;
|
852
|
+
|
853
|
+
rows.push({ id: Date.now(), value: obj });
|
854
|
+
});
|
855
|
+
return { code: 1, data: rows };
|
843
856
|
}
|
857
|
+
|
844
858
|
var rows = [];
|
845
859
|
|
846
860
|
for await (var val of body.rows) {
|
@@ -853,6 +867,31 @@ const query_db = async function (e, db, app_id_reference, table_obj) {
|
|
853
867
|
value: { udfData: val.doc.udfData, _id: val.id },
|
854
868
|
});
|
855
869
|
}
|
870
|
+
|
871
|
+
// const reduce_rows = () => {
|
872
|
+
// const reduce_obj = body.docs.reduce(
|
873
|
+
// (params, data) => {
|
874
|
+
// const fx = (val, idx) => {
|
875
|
+
// const group_by_field = data[params.sort[idx]];
|
876
|
+
|
877
|
+
// if (params.sort[idx + 1]) {
|
878
|
+
// val[group_by_field] = val[group_by_field] ?? {};
|
879
|
+
// val[group_by_field][data[params.sort[idx + 1]]] = 0;
|
880
|
+
// idx++;
|
881
|
+
// fx(val[group_by_field], idx);
|
882
|
+
// return;
|
883
|
+
// }
|
884
|
+
|
885
|
+
// val[group_by_field] = val[group_by_field] ?? 0;
|
886
|
+
// val[group_by_field] += 1;
|
887
|
+
// };
|
888
|
+
// fx(params.group, 0);
|
889
|
+
|
890
|
+
// return params;
|
891
|
+
// },
|
892
|
+
// { sort: opt.sort, group: {} }
|
893
|
+
// );}
|
894
|
+
|
856
895
|
return { code: 1, data: { rows: rows, total_rows: rows.length } };
|
857
896
|
} catch (error) {
|
858
897
|
return { code: -1, data: error };
|