baja-lite 1.0.2 → 1.0.3
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/cjs/code.d.ts +0 -0
- package/cjs/code.js +2 -0
- package/cjs/index.d.ts +0 -1
- package/cjs/index.js +0 -1
- package/cjs/object.js +3 -7
- package/cjs/sql.d.ts +44 -18
- package/cjs/sql.js +453 -58
- package/cjs/string.d.ts +0 -1
- package/cjs/string.js +1 -6
- package/cjs/test-mysql.js +3 -3
- package/es/code.d.ts +0 -0
- package/es/code.js +2 -0
- package/es/index.d.ts +0 -1
- package/es/index.js +0 -1
- package/es/object.js +3 -4
- package/es/sql.d.ts +44 -18
- package/es/sql.js +453 -58
- package/es/string.d.ts +0 -1
- package/es/string.js +0 -4
- package/es/test-mysql.js +3 -3
- package/package.json +19 -20
- package/src/code.ts +1 -0
- package/src/constant.ts +14 -0
- package/src/error.ts +11 -0
- package/src/fn.ts +287 -0
- package/src/index.ts +7 -0
- package/src/math.ts +367 -0
- package/src/object.ts +213 -0
- package/src/redis.ts +0 -0
- package/src/set-ex.ts +362 -0
- package/src/sql.ts +4021 -0
- package/src/string.ts +111 -0
- package/src/test-mysql.ts +96 -0
- package/src/test-sqlite.ts +78 -0
- package/src/test.ts +2 -0
- package/cjs/now.d.ts +0 -7
- package/cjs/now.js +0 -26
- package/es/now.d.ts +0 -7
- package/es/now.js +0 -16
package/src/string.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通过uri获取key
|
|
3
|
+
* @param uri
|
|
4
|
+
*/
|
|
5
|
+
export const getPicKey = (uri: string): string => {
|
|
6
|
+
const arr = /key=([0-9a-zA-Z.]+)/.exec(uri);
|
|
7
|
+
if (arr && arr.length === 2) {
|
|
8
|
+
return arr[1]!;
|
|
9
|
+
}
|
|
10
|
+
return uri;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const emptyString = (source: any, skipEmptyString = true): boolean => {
|
|
14
|
+
return (
|
|
15
|
+
source === null ||
|
|
16
|
+
source === undefined ||
|
|
17
|
+
(skipEmptyString === true && (source === '' || `${ source }`.replace(/\s/g, '') === ''))
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const notEmptyString = (source: any, skipEmptyString = true): boolean => {
|
|
22
|
+
return emptyString(source, skipEmptyString) === false;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const safeString = (source?: string): string => {
|
|
26
|
+
if (source) {
|
|
27
|
+
return `${ source }`.replace(/'/g, '');
|
|
28
|
+
}
|
|
29
|
+
return '';
|
|
30
|
+
};
|
|
31
|
+
export const trimObject = <T>(data: any): T => {
|
|
32
|
+
if (data) {
|
|
33
|
+
for (const k in data) {
|
|
34
|
+
if (typeof data[k] === 'string') {
|
|
35
|
+
data[k] = data[k].trim();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const randomNumber = (len: number): string => {
|
|
43
|
+
return `${ parseInt(`${ (Math.random() * 9 + 1) * Math.pow(10, (len - 1)) }`, 10) }`;
|
|
44
|
+
};
|
|
45
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
46
|
+
const charLen = chars.length;
|
|
47
|
+
export const randomString = (len: number): string => {
|
|
48
|
+
return Array.from(new Array(len)).map(() => chars.charAt(Math.floor(Math.random() * charLen))).join('');
|
|
49
|
+
};
|
|
50
|
+
const chars2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
51
|
+
const charLen2 = chars2.length;
|
|
52
|
+
export const randomString2 = (len: number): string => {
|
|
53
|
+
return Array.from(new Array(len)).map(() => chars2.charAt(Math.floor(Math.random() * charLen2))).join('');
|
|
54
|
+
};
|
|
55
|
+
const chars3 = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
56
|
+
const charLen3 = chars3.length;
|
|
57
|
+
export const randomString3 = (len: number): string => {
|
|
58
|
+
return Array.from(new Array(len)).map(() => chars3.charAt(Math.floor(Math.random() * charLen3))).join('');
|
|
59
|
+
};
|
|
60
|
+
export const buildWxStr = (data: {[key: string]: string}, maxLabelLength: number, ...titles: string[]) => {
|
|
61
|
+
let str = titles.join('\r\n');
|
|
62
|
+
str += '\r\n\r\n';
|
|
63
|
+
const items = new Array<string>();
|
|
64
|
+
// const maxLength = maxLabelLength * 2;
|
|
65
|
+
for (const [key, value] of Object.entries(data)) {
|
|
66
|
+
if (notEmptyString(value)) {
|
|
67
|
+
const len = maxLabelLength - key.length;
|
|
68
|
+
items.push(`${ key }:${ ''.padEnd(len * 3 + (len > 0 ? 1 : 0), ' ') }${ value }`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
str += items.join('\r\n');
|
|
72
|
+
return str;
|
|
73
|
+
};
|
|
74
|
+
const chinese = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/g;
|
|
75
|
+
const table = {
|
|
76
|
+
'!': '!',
|
|
77
|
+
'¥': '$',
|
|
78
|
+
'…': '.',
|
|
79
|
+
'(': '(',
|
|
80
|
+
')': ')',
|
|
81
|
+
'《': '<',
|
|
82
|
+
'》': '>',
|
|
83
|
+
'?': '?',
|
|
84
|
+
':': ':',
|
|
85
|
+
'“': `'`,
|
|
86
|
+
'”': `'`,
|
|
87
|
+
'’': `'`,
|
|
88
|
+
'‘': `'`,
|
|
89
|
+
',': ',',
|
|
90
|
+
'。': '.',
|
|
91
|
+
'、': '/',
|
|
92
|
+
';': ';',
|
|
93
|
+
'〈': '<',
|
|
94
|
+
'〉': '>',
|
|
95
|
+
'【': '[',
|
|
96
|
+
'】': ']',
|
|
97
|
+
'『': '[',
|
|
98
|
+
'』': ']',
|
|
99
|
+
'「': '[',
|
|
100
|
+
'」': ']',
|
|
101
|
+
'﹃': '[',
|
|
102
|
+
'﹄': ']',
|
|
103
|
+
'〔': '(',
|
|
104
|
+
'〕': ')',
|
|
105
|
+
'—': '-',
|
|
106
|
+
'~': '~',
|
|
107
|
+
'﹏': '~'
|
|
108
|
+
};
|
|
109
|
+
export const replaceChineseCode = (str: string) => {
|
|
110
|
+
return str.replace(chinese, (a: string) => table[a] || '');
|
|
111
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { SqlService, Boot, Field, DB, DBType, DeleteMode, SqlType, InsertMode, TemplateResult, SelectResult } from './sql';
|
|
2
|
+
|
|
3
|
+
class AmaFuck2 {
|
|
4
|
+
@Field({ type: SqlType.varchar, length: 200 })
|
|
5
|
+
site?: string;
|
|
6
|
+
@Field({ type: SqlType.varchar, length: 200 })
|
|
7
|
+
SellerSKU2?: string;
|
|
8
|
+
@Field({ type: SqlType.varchar, id: true, length: 200 })
|
|
9
|
+
SellerSKU?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@DB({
|
|
13
|
+
tableName: 'ama_fuck2', clz: AmaFuck2, dbType: DBType.Mysql
|
|
14
|
+
})
|
|
15
|
+
class AmaService2 extends SqlService<AmaFuck2>{
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
async function go2() {
|
|
19
|
+
await Boot({
|
|
20
|
+
Mysql: {
|
|
21
|
+
host: '39.98.58.252',
|
|
22
|
+
port: 3308,
|
|
23
|
+
user: 'root',
|
|
24
|
+
password: 'Eme!2#456$&*',
|
|
25
|
+
// 数据库名
|
|
26
|
+
database: 'dmce',
|
|
27
|
+
debug: false
|
|
28
|
+
},
|
|
29
|
+
log: 'info'
|
|
30
|
+
});
|
|
31
|
+
const service = new AmaService2();
|
|
32
|
+
const ret = await service.transaction<number>({
|
|
33
|
+
fn: async conn => {
|
|
34
|
+
const list = new Array<AmaFuck2>({
|
|
35
|
+
SellerSKU: 'SellerSKU1',
|
|
36
|
+
site: 'site1'
|
|
37
|
+
}, {
|
|
38
|
+
SellerSKU: 'SellerSKU2',
|
|
39
|
+
SellerSKU2: 'SellerSKU22',
|
|
40
|
+
}, {
|
|
41
|
+
SellerSKU2: 'SellerSKU23',
|
|
42
|
+
SellerSKU: 'SellerSKU3',
|
|
43
|
+
site: 'site3'
|
|
44
|
+
}, {
|
|
45
|
+
SellerSKU2: 'SellerSKU24',
|
|
46
|
+
SellerSKU: 'SellerSKU4',
|
|
47
|
+
site: 'site4'
|
|
48
|
+
}, {
|
|
49
|
+
SellerSKU2: '',
|
|
50
|
+
SellerSKU: 'SellerSKU5',
|
|
51
|
+
site: undefined
|
|
52
|
+
});
|
|
53
|
+
const rt = await service.insert({
|
|
54
|
+
data: list,
|
|
55
|
+
conn, skipEmptyString: false,
|
|
56
|
+
mode: InsertMode.InsertWithTempTable
|
|
57
|
+
});
|
|
58
|
+
console.log(11, rt);
|
|
59
|
+
const rt2 = await service.update({
|
|
60
|
+
data: {
|
|
61
|
+
SellerSKU: 'SellerSKU1',
|
|
62
|
+
SellerSKU2: 'SellerSKU21',
|
|
63
|
+
site: 'site1'
|
|
64
|
+
},
|
|
65
|
+
conn, skipEmptyString: false
|
|
66
|
+
});
|
|
67
|
+
console.log(22, rt2);
|
|
68
|
+
const rt3 = await service.delete({
|
|
69
|
+
where: [
|
|
70
|
+
{ SellerSKU2: 'SellerSKU23', SellerSKU: 'SellerSKU3' }
|
|
71
|
+
],
|
|
72
|
+
mode: DeleteMode.TempTable,
|
|
73
|
+
conn
|
|
74
|
+
});
|
|
75
|
+
console.log(33, rt3);
|
|
76
|
+
const rt4 = await service.template({
|
|
77
|
+
where: { SellerSKU2: 'SellerSKU22', SellerSKU: 'SellerSKU2' },
|
|
78
|
+
templateResult: TemplateResult.Count
|
|
79
|
+
})
|
|
80
|
+
console.log(44, rt4);
|
|
81
|
+
|
|
82
|
+
const rt5 = await service.select<string>({
|
|
83
|
+
sql: `SELECT SellerSKU FROM ama_fuck2 WHERE SellerSKU LIKE CONCAT(:sku, '%');SELECT SellerSKU FROM ama_fuck2 WHERE SellerSKU LIKE CONCAT(:sku, '%');SELECT SellerSKU FROM ama_fuck2 WHERE SellerSKU LIKE CONCAT(:sku, '%')`,
|
|
84
|
+
params: {sku: 'SellerSKU4'},
|
|
85
|
+
selectResult: SelectResult.Many_Row_One_Column
|
|
86
|
+
})
|
|
87
|
+
console.log(55, rt5);
|
|
88
|
+
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return ret;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
go2();
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SqlService, Boot, Field, SqlType, DB, DBType, SyncMode, DeleteMode, InsertMode } from './sql';
|
|
2
|
+
|
|
3
|
+
class AmaFuck {
|
|
4
|
+
@Field({ type: SqlType.varchar })
|
|
5
|
+
site?: string;
|
|
6
|
+
@Field({ type: SqlType.varchar })
|
|
7
|
+
SellerSKU2?: string;
|
|
8
|
+
@Field({ type: SqlType.varchar, id: true })
|
|
9
|
+
SellerSKU?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@DB({
|
|
13
|
+
tableName: 'ama_fuck2', clz: AmaFuck, dbType: DBType.Sqlite, sqliteVersion: '0.0.3'
|
|
14
|
+
})
|
|
15
|
+
class AmaService extends SqlService<AmaFuck>{
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
async function go() {
|
|
19
|
+
await Boot({
|
|
20
|
+
Sqlite: 'd:1.db',
|
|
21
|
+
log: 'info'
|
|
22
|
+
});
|
|
23
|
+
const service = new AmaService();
|
|
24
|
+
const ret = service.transaction<number>({
|
|
25
|
+
sync: SyncMode.Sync,
|
|
26
|
+
fn: conn => {
|
|
27
|
+
const list = new Array<AmaFuck>({
|
|
28
|
+
SellerSKU: '1',
|
|
29
|
+
site: '111'
|
|
30
|
+
}, {
|
|
31
|
+
SellerSKU: '2',
|
|
32
|
+
SellerSKU2: '22',
|
|
33
|
+
}, {
|
|
34
|
+
SellerSKU2: '33',
|
|
35
|
+
SellerSKU: '3',
|
|
36
|
+
site: '333'
|
|
37
|
+
}, {
|
|
38
|
+
SellerSKU2: '44',
|
|
39
|
+
SellerSKU: '4',
|
|
40
|
+
site: '444'
|
|
41
|
+
}, {
|
|
42
|
+
SellerSKU2: '',
|
|
43
|
+
SellerSKU: '66',
|
|
44
|
+
site: undefined
|
|
45
|
+
});
|
|
46
|
+
const rt = service.insert({
|
|
47
|
+
sync: SyncMode.Sync,
|
|
48
|
+
data: list,
|
|
49
|
+
conn, skipEmptyString: false, mode: InsertMode.InsertWithTempTable
|
|
50
|
+
});
|
|
51
|
+
console.log(rt);
|
|
52
|
+
const rt2 = service.update({
|
|
53
|
+
sync: SyncMode.Sync,
|
|
54
|
+
data: list,
|
|
55
|
+
conn, skipEmptyString: false
|
|
56
|
+
});
|
|
57
|
+
console.log(rt2);
|
|
58
|
+
const rt3 = service.delete({
|
|
59
|
+
sync: SyncMode.Sync,
|
|
60
|
+
where: [
|
|
61
|
+
{ SellerSKU2: '11', SellerSKU: '1' },
|
|
62
|
+
{ SellerSKU2: '22', SellerSKU: '2' },
|
|
63
|
+
{ SellerSKU2: '33', SellerSKU: '3' }
|
|
64
|
+
],
|
|
65
|
+
mode: DeleteMode.TempTable
|
|
66
|
+
});
|
|
67
|
+
console.log(rt3);
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return ret;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
go();
|
package/src/test.ts
ADDED
package/cjs/now.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const dateTime = "YYYY-MM-DD HH:mm:ss";
|
|
2
|
-
export declare const dateXSDTime = "YYYY-MM-DDTHH:mm:ss";
|
|
3
|
-
export declare const date = "YYYY-MM-DD";
|
|
4
|
-
export declare const nowTime: () => string;
|
|
5
|
-
export declare const nowDate: () => string;
|
|
6
|
-
export declare const nowTimeXSD: () => string;
|
|
7
|
-
export declare const dateFormat: (str: any, format?: string) => any;
|
package/cjs/now.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.dateFormat = exports.nowTimeXSD = exports.nowDate = exports.nowTime = exports.date = exports.dateXSDTime = exports.dateTime = void 0;
|
|
7
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
-
exports.dateTime = 'YYYY-MM-DD HH:mm:ss';
|
|
9
|
-
exports.dateXSDTime = 'YYYY-MM-DDTHH:mm:ss';
|
|
10
|
-
exports.date = 'YYYY-MM-DD';
|
|
11
|
-
const nowTime = () => (0, dayjs_1.default)().format(exports.dateTime);
|
|
12
|
-
exports.nowTime = nowTime;
|
|
13
|
-
const nowDate = () => (0, dayjs_1.default)().format(exports.date);
|
|
14
|
-
exports.nowDate = nowDate;
|
|
15
|
-
const nowTimeXSD = () => (0, dayjs_1.default)().format(exports.dateXSDTime);
|
|
16
|
-
exports.nowTimeXSD = nowTimeXSD;
|
|
17
|
-
const dateFormat = (str, format) => {
|
|
18
|
-
if (str) {
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
20
|
-
return (0, dayjs_1.default)(str).format(format || exports.dateTime);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
return str;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
exports.dateFormat = dateFormat;
|
package/es/now.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const dateTime = "YYYY-MM-DD HH:mm:ss";
|
|
2
|
-
export declare const dateXSDTime = "YYYY-MM-DDTHH:mm:ss";
|
|
3
|
-
export declare const date = "YYYY-MM-DD";
|
|
4
|
-
export declare const nowTime: () => string;
|
|
5
|
-
export declare const nowDate: () => string;
|
|
6
|
-
export declare const nowTimeXSD: () => string;
|
|
7
|
-
export declare const dateFormat: (str: any, format?: string) => any;
|
package/es/now.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import day from 'dayjs';
|
|
2
|
-
export const dateTime = 'YYYY-MM-DD HH:mm:ss';
|
|
3
|
-
export const dateXSDTime = 'YYYY-MM-DDTHH:mm:ss';
|
|
4
|
-
export const date = 'YYYY-MM-DD';
|
|
5
|
-
export const nowTime = () => day().format(dateTime);
|
|
6
|
-
export const nowDate = () => day().format(date);
|
|
7
|
-
export const nowTimeXSD = () => day().format(dateXSDTime);
|
|
8
|
-
export const dateFormat = (str, format) => {
|
|
9
|
-
if (str) {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
11
|
-
return day(str).format(format || dateTime);
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
return str;
|
|
15
|
-
}
|
|
16
|
-
};
|