baja-lite 1.5.21 → 1.5.23
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/README.md +1 -1
- package/object.d.ts +6 -0
- package/object.js +18 -0
- package/package.json +1 -1
- package/sql.js +24 -14
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
|
|
2
|
-
[
|
|
2
|
+
[](https://deepwiki.com/void-soul/baja-lite)
|
package/object.d.ts
CHANGED
|
@@ -111,6 +111,12 @@ export declare const arraySplit: <T = any>(datas: T[], { everyLength, groupCount
|
|
|
111
111
|
* @returns
|
|
112
112
|
*/
|
|
113
113
|
export declare const assginObject: <T extends Object>(source: T, ...os: T[]) => void;
|
|
114
|
+
/**
|
|
115
|
+
* 去除数组中重复数据,同时可以通过each函数为每个数据执行某项操作
|
|
116
|
+
* @param source
|
|
117
|
+
* @param each
|
|
118
|
+
*/
|
|
119
|
+
export declare const distinctArray: <T extends Object>(source: T[], keys: (keyof T)[], each?: (data: T) => void) => T[];
|
|
114
120
|
export declare const P2C: (pro: string, IF?: boolean) => string;
|
|
115
121
|
export declare const C2P: (pro: string, IF?: boolean) => string;
|
|
116
122
|
export declare function C2P2<T extends Object = any, L extends Object = T>(datas: L[], hump?: boolean, convert?: Record<string, (data: any) => any>): T[];
|
package/object.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SetEx } from 'baja-lite-field';
|
|
1
2
|
import * as ite from 'iterare';
|
|
2
3
|
const iterate = ite.iterate;
|
|
3
4
|
/**
|
|
@@ -246,6 +247,23 @@ export const arraySplit = (datas, { everyLength = 0, groupCount = 0 } = {}) => {
|
|
|
246
247
|
export const assginObject = (source, ...os) => {
|
|
247
248
|
os.forEach(o => Object.entries(o).forEach(([key, value]) => value !== null && value !== undefined && `${value}`.trim() !== '' && (source[key] = value)));
|
|
248
249
|
};
|
|
250
|
+
/**
|
|
251
|
+
* 去除数组中重复数据,同时可以通过each函数为每个数据执行某项操作
|
|
252
|
+
* @param source
|
|
253
|
+
* @param each
|
|
254
|
+
*/
|
|
255
|
+
export const distinctArray = (source, keys, each) => {
|
|
256
|
+
const set = new SetEx({ key: '___id' });
|
|
257
|
+
for (const item of source) {
|
|
258
|
+
const _item = item;
|
|
259
|
+
_item.___id = keys.map(key => item[key]).join('_');
|
|
260
|
+
if (each) {
|
|
261
|
+
each(item);
|
|
262
|
+
}
|
|
263
|
+
set.add(_item);
|
|
264
|
+
}
|
|
265
|
+
return set.toArray();
|
|
266
|
+
};
|
|
249
267
|
const P2CEX = /[A-Z]/g;
|
|
250
268
|
export const P2C = (pro, IF = true) => (IF ? pro.replace(P2CEX, (a) => `_${a.toLowerCase()}`) : pro);
|
|
251
269
|
const C2PEX = /_([a-z])/g;
|
package/package.json
CHANGED
package/sql.js
CHANGED
|
@@ -1386,12 +1386,17 @@ class Build {
|
|
|
1386
1386
|
}
|
|
1387
1387
|
/**
|
|
1388
1388
|
*
|
|
1389
|
-
* beetween and
|
|
1390
|
-
* etc.
|
|
1391
|
-
*
|
|
1392
|
-
* createtime
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
1389
|
+
* # beetween and
|
|
1390
|
+
* ## etc.
|
|
1391
|
+
* ```
|
|
1392
|
+
* {{#between}} AND t.createtime ({{createtime}}) {{/between}}
|
|
1393
|
+
* // 其中:
|
|
1394
|
+
* createtime = '1,2'
|
|
1395
|
+
* // 或者
|
|
1396
|
+
* createtime = ['1', '2']
|
|
1397
|
+
* // 将生成:
|
|
1398
|
+
* AND t.createtime BETWEEN '1' AND '2'
|
|
1399
|
+
* ```
|
|
1395
1400
|
* @returns
|
|
1396
1401
|
* @memberof Build
|
|
1397
1402
|
*/
|
|
@@ -1401,8 +1406,13 @@ class Build {
|
|
|
1401
1406
|
if (/\(([\w\W]+)\)/.exec(result)) {
|
|
1402
1407
|
return render(text).replace(/\(([\w\W]+)\)/, (a, b) => {
|
|
1403
1408
|
if (a && b) {
|
|
1404
|
-
|
|
1405
|
-
|
|
1409
|
+
if (typeof b === 'string') {
|
|
1410
|
+
const xx = b.split(',');
|
|
1411
|
+
return ` BETWEEN '${xx[0]}' AND '${xx[1]}'`;
|
|
1412
|
+
}
|
|
1413
|
+
else {
|
|
1414
|
+
return ` BETWEEN '${b[0]}' AND '${b[1]}'`;
|
|
1415
|
+
}
|
|
1406
1416
|
}
|
|
1407
1417
|
else {
|
|
1408
1418
|
return '';
|
|
@@ -3783,12 +3793,12 @@ class StreamQuery {
|
|
|
3783
3793
|
page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
|
|
3784
3794
|
distinct(on = true) { this._distinct = on; return this; }
|
|
3785
3795
|
/** COUNT(DISTINCT key) */
|
|
3786
|
-
countDistinct(key, countName) { this._columns.push(`COUNT(DISTINCT t.${this[_fields][String(key)]?.C2()}) ${countName ||
|
|
3796
|
+
countDistinct(key, countName) { this._columns.push(`COUNT(DISTINCT t.${this[_fields][String(key)]?.C2()}) ${countName || this[_fields][String(key)]?.C2()}`); return this; }
|
|
3787
3797
|
count(countName) { this._columns.push(`COUNT(1) ${countName ?? 'ct'}`); return this; }
|
|
3788
|
-
sum(key, legName, distinct) { this._columns.push(`SUM(${distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}) ${legName ||
|
|
3789
|
-
avg(key, legName, distinct) { this._columns.push(`AVG(${distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}) ${legName ||
|
|
3790
|
-
max(key, legName, distinct) { this._columns.push(`MAX(${distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}) ${legName ||
|
|
3791
|
-
min(key, legName, distinct) { this._columns.push(`MIN(${distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}) ${legName ||
|
|
3798
|
+
sum(key, legName, distinct) { this._columns.push(`SUM(${distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}) ${legName || this[_fields][String(key)]?.C2()}`); return this; }
|
|
3799
|
+
avg(key, legName, distinct) { this._columns.push(`AVG(${distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}) ${legName || this[_fields][String(key)]?.C2()}`); return this; }
|
|
3800
|
+
max(key, legName, distinct) { this._columns.push(`MAX(${distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}) ${legName || this[_fields][String(key)]?.C2()}`); return this; }
|
|
3801
|
+
min(key, legName, distinct) { this._columns.push(`MIN(${distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}) ${legName || this[_fields][String(key)]?.C2()}`); return this; }
|
|
3792
3802
|
/** GROUP_CONCAT([DISTINCT] key [ORDER BY :asc ASC] [ORDER BY :asc DESC] [SEPARATOR :separator]) */
|
|
3793
3803
|
groupConcat(key, param) {
|
|
3794
3804
|
this._columns.push(`GROUP_CONCAT(
|
|
@@ -3796,7 +3806,7 @@ class StreamQuery {
|
|
|
3796
3806
|
${param && param.asc && param.asc.length > 0 ? `ORDER BY ${param.asc.map(i => `t.${this[_fields][String(i)]?.C2()} ASC`)} ` : ''}
|
|
3797
3807
|
${param && param.desc && param.desc.length > 0 ? `${param && param.asc && param.asc.length > 0 ? '' : 'ORDER BY'} ${param.desc.map(i => `t.${this[_fields][String(i)]?.C2()} DESC`)} ` : ''}
|
|
3798
3808
|
SEPARATOR '${param && param.separator || ','}'
|
|
3799
|
-
) ${param && param.groupName ||
|
|
3809
|
+
) ${param && param.groupName || this[_fields][String(key)]?.C2()}`);
|
|
3800
3810
|
return this;
|
|
3801
3811
|
}
|
|
3802
3812
|
select(...key) { this._columns.push(...(key.map(k => `t.${this[_fields][String(k)].C3()}`))); return this; }
|