baja-lite 1.6.4 → 1.6.5
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/boot-remote.d.ts +2 -0
- package/{src/boot-remote.ts → boot-remote.js} +63 -64
- package/boot.d.ts +2 -0
- package/{src/boot.ts → boot.js} +163 -170
- package/code.d.ts +2 -0
- package/{src/code.ts → code.js} +405 -414
- package/convert-xml.d.ts +10 -0
- package/{src/convert-xml.ts → convert-xml.js} +410 -460
- package/error.d.ts +5 -0
- package/error.js +13 -0
- package/event.d.ts +10 -0
- package/event.js +38 -0
- package/fn.d.ts +128 -0
- package/fn.js +172 -0
- package/{src/index.ts → index.d.ts} +10 -11
- package/index.js +10 -0
- package/math.d.ts +83 -0
- package/math.js +451 -0
- package/object.d.ts +126 -0
- package/object.js +321 -0
- package/package.json +1 -1
- package/snowflake.d.ts +12 -0
- package/{src/snowflake.ts → snowflake.js} +108 -127
- package/sql.d.ts +2148 -0
- package/sql.js +5370 -0
- package/sqlite.d.ts +32 -0
- package/{src/sqlite.ts → sqlite.js} +156 -157
- package/string.d.ts +17 -0
- package/string.js +105 -0
- package/test-mysql.d.ts +2 -0
- package/test-mysql.js +114 -0
- package/test-postgresql.d.ts +2 -0
- package/{src/test-postgresql.ts → test-postgresql.js} +91 -80
- package/test-sqlite.d.ts +1 -0
- package/{src/test-sqlite.ts → test-sqlite.js} +90 -80
- package/test-xml.d.ts +1 -0
- package/{src/test-xml.ts → test-xml.js} +2 -2
- package/test.d.ts +1 -0
- package/{src/test.ts → test.js} +2 -3
- package/wx/base.d.ts +11 -0
- package/wx/base.js +78 -0
- package/wx/mini.d.ts +52 -0
- package/wx/mini.js +112 -0
- package/wx/organ.d.ts +65 -0
- package/wx/organ.js +171 -0
- package/{src/wx/types.ts → wx/types.d.ts} +560 -549
- package/wx/types.js +1 -0
- package/{src/wx.ts → wx.d.ts} +3 -3
- package/wx.js +3 -0
- package/.eslintignore +0 -7
- package/.eslintrc.cjs +0 -89
- package/.prettierrc +0 -7
- package/.vscode/settings.json +0 -9
- package/ci.js +0 -33
- package/package-cjs.json +0 -17
- package/pnpm-lock.yaml +0 -2840
- package/pnpm-workspace.yaml +0 -2
- package/src/error.ts +0 -11
- package/src/event.ts +0 -34
- package/src/fn.ts +0 -295
- package/src/math.ts +0 -405
- package/src/object.ts +0 -342
- package/src/sql.ts +0 -5529
- package/src/string.ts +0 -111
- package/src/test-mysql.ts +0 -148
- package/src/wx/base.ts +0 -77
- package/src/wx/mini.ts +0 -147
- package/src/wx/organ.ts +0 -290
- package/tsconfig.cjs.json +0 -42
- package/tsconfig.json +0 -44
- package/xml/event-report.xml +0 -13
- package/yarn.lock +0 -1977
- /package/{Readme.md → README.md} +0 -0
package/sqlite.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SqliteRemoteInterface } from './sql.js';
|
|
2
|
+
export declare abstract class SqliteRemoteClass implements SqliteRemoteInterface {
|
|
3
|
+
private dbList;
|
|
4
|
+
/** 原始存放路径 */
|
|
5
|
+
abstract getStoreName(dbName: string): string;
|
|
6
|
+
/** 导入时,备份源文件路径 */
|
|
7
|
+
abstract getBackName(dbName: string): string;
|
|
8
|
+
abstract BetterSqlite3: any;
|
|
9
|
+
/** 实现复制 */
|
|
10
|
+
abstract cpSync(from: string, to: string, option?: {
|
|
11
|
+
force: true;
|
|
12
|
+
}): void;
|
|
13
|
+
/**
|
|
14
|
+
* 设置可执行权限
|
|
15
|
+
```
|
|
16
|
+
const fd = openSync(dbPath, 1);
|
|
17
|
+
fchmodSync(fd, 777);
|
|
18
|
+
closeSync(fd);
|
|
19
|
+
```
|
|
20
|
+
*/
|
|
21
|
+
abstract setMod(name: string): void;
|
|
22
|
+
abstract trace: boolean;
|
|
23
|
+
execute(inData: Uint8Array): Promise<Uint8Array>;
|
|
24
|
+
pluck(inData: Uint8Array): Promise<Uint8Array>;
|
|
25
|
+
get(inData: Uint8Array): Promise<Uint8Array>;
|
|
26
|
+
raw(inData: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
query(inData: Uint8Array): Promise<Uint8Array>;
|
|
28
|
+
initDB(dbName: string): void;
|
|
29
|
+
export(dbName: string, exportPath: string): Promise<void>;
|
|
30
|
+
restore(dbName: string, importPath: string): void;
|
|
31
|
+
close(dbName?: string): void;
|
|
32
|
+
}
|
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
import { decode, encode } from "@msgpack/msgpack";
|
|
2
|
-
import Sqlstring from 'sqlstring';
|
|
3
|
-
import { snowflake } from './snowflake.js';
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
logger.debug(sql, params ?? '');
|
|
29
|
-
try {
|
|
30
|
-
if (!sql) { return encode({ affectedRows: 0, insertId: 0n }, { extensionCodec }); };
|
|
31
|
-
if (this.trace) {
|
|
32
|
-
logger.trace(Sqlstring.format(sql!, params));
|
|
33
|
-
}
|
|
34
|
-
const result = this.dbList[dbName].prepare(sql).run(params ?? {});
|
|
35
|
-
if (this.trace) {
|
|
36
|
-
logger.trace(result);
|
|
37
|
-
}
|
|
38
|
-
const { changes, lastInsertRowid } = result;
|
|
39
|
-
return encode({ affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n }, { extensionCodec });
|
|
40
|
-
} catch (error) {
|
|
1
|
+
import { decode, encode } from "@msgpack/msgpack";
|
|
2
|
+
import Sqlstring from 'sqlstring';
|
|
3
|
+
import { snowflake } from './snowflake.js';
|
|
4
|
+
import { extensionCodec, logger } from './sql.js';
|
|
5
|
+
export class SqliteRemoteClass {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.dbList = {};
|
|
8
|
+
}
|
|
9
|
+
async execute(inData) {
|
|
10
|
+
const [dbName, sql, params] = decode(inData);
|
|
11
|
+
logger.debug(sql, params ?? '');
|
|
12
|
+
try {
|
|
13
|
+
if (!sql) {
|
|
14
|
+
return encode({ affectedRows: 0, insertId: 0n }, { extensionCodec });
|
|
15
|
+
}
|
|
16
|
+
;
|
|
17
|
+
if (this.trace) {
|
|
18
|
+
logger.trace(Sqlstring.format(sql, params));
|
|
19
|
+
}
|
|
20
|
+
const result = this.dbList[dbName].prepare(sql).run(params ?? {});
|
|
21
|
+
if (this.trace) {
|
|
22
|
+
logger.trace(result);
|
|
23
|
+
}
|
|
24
|
+
const { changes, lastInsertRowid } = result;
|
|
25
|
+
return encode({ affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n }, { extensionCodec });
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
41
28
|
logger.error(`
|
|
42
29
|
error: ${error},
|
|
43
30
|
sql: ${sql},
|
|
44
31
|
params: ${params}
|
|
45
|
-
`);
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async pluck(inData
|
|
50
|
-
const [dbName, sql, params] = decode(inData)
|
|
51
|
-
logger.debug(sql, params ?? '');
|
|
52
|
-
try {
|
|
53
|
-
logger.debug(sql, params ?? '');
|
|
54
|
-
if (!sql) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
`);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async pluck(inData) {
|
|
37
|
+
const [dbName, sql, params] = decode(inData);
|
|
38
|
+
logger.debug(sql, params ?? '');
|
|
39
|
+
try {
|
|
40
|
+
logger.debug(sql, params ?? '');
|
|
41
|
+
if (!sql) {
|
|
42
|
+
return encode(null);
|
|
43
|
+
}
|
|
44
|
+
;
|
|
45
|
+
if (this.trace) {
|
|
46
|
+
logger.trace(Sqlstring.format(sql, params));
|
|
47
|
+
}
|
|
48
|
+
return encode(this.dbList[dbName].prepare(sql).pluck().get(params ?? {}), { extensionCodec });
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
60
51
|
logger.error(`
|
|
61
52
|
error: ${error},
|
|
62
53
|
sql: ${sql},
|
|
63
54
|
params: ${params}
|
|
64
|
-
`);
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async get(inData
|
|
69
|
-
const [dbName, sql, params] = decode(inData)
|
|
70
|
-
logger.debug(sql, params ?? '');
|
|
71
|
-
try {
|
|
72
|
-
if (this.trace) {
|
|
73
|
-
logger.trace(Sqlstring.format(sql
|
|
74
|
-
}
|
|
75
|
-
return encode(this.dbList[dbName].prepare(sql).get(params ?? {}), { extensionCodec });
|
|
76
|
-
}
|
|
55
|
+
`);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async get(inData) {
|
|
60
|
+
const [dbName, sql, params] = decode(inData);
|
|
61
|
+
logger.debug(sql, params ?? '');
|
|
62
|
+
try {
|
|
63
|
+
if (this.trace) {
|
|
64
|
+
logger.trace(Sqlstring.format(sql, params));
|
|
65
|
+
}
|
|
66
|
+
return encode(this.dbList[dbName].prepare(sql).get(params ?? {}), { extensionCodec });
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
77
69
|
logger.error(`
|
|
78
70
|
error: ${error},
|
|
79
71
|
sql: ${sql},
|
|
80
72
|
params: ${params}
|
|
81
|
-
`);
|
|
82
|
-
throw error;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async raw(inData
|
|
86
|
-
const [dbName, sql, params] = decode(inData)
|
|
87
|
-
logger.debug(sql, params ?? '');
|
|
88
|
-
try {
|
|
89
|
-
if (!sql) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
73
|
+
`);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async raw(inData) {
|
|
78
|
+
const [dbName, sql, params] = decode(inData);
|
|
79
|
+
logger.debug(sql, params ?? '');
|
|
80
|
+
try {
|
|
81
|
+
if (!sql) {
|
|
82
|
+
return encode([]);
|
|
83
|
+
}
|
|
84
|
+
;
|
|
85
|
+
if (this.trace) {
|
|
86
|
+
logger.trace(Sqlstring.format(sql, params));
|
|
87
|
+
}
|
|
88
|
+
return encode(this.dbList[dbName].prepare(sql).raw().all(params ?? {}), { extensionCodec });
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
95
91
|
logger.error(`
|
|
96
92
|
error: ${error},
|
|
97
93
|
sql: ${sql},
|
|
98
94
|
params: ${params}
|
|
99
|
-
`);
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async query(inData
|
|
104
|
-
const [dbName, sql, params] = decode(inData)
|
|
105
|
-
logger.debug(sql, params ?? '');
|
|
106
|
-
try {
|
|
107
|
-
if (!sql) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
95
|
+
`);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async query(inData) {
|
|
100
|
+
const [dbName, sql, params] = decode(inData);
|
|
101
|
+
logger.debug(sql, params ?? '');
|
|
102
|
+
try {
|
|
103
|
+
if (!sql) {
|
|
104
|
+
encode([]);
|
|
105
|
+
}
|
|
106
|
+
;
|
|
107
|
+
if (this.trace) {
|
|
108
|
+
logger.trace(Sqlstring.format(sql, params));
|
|
109
|
+
}
|
|
110
|
+
return encode(this.dbList[dbName].prepare(sql).all(params ?? {}), { extensionCodec });
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
113
|
logger.error(`
|
|
114
114
|
error: ${error},
|
|
115
115
|
sql: ${sql},
|
|
116
116
|
params: ${params}
|
|
117
|
-
`);
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
initDB(dbName
|
|
122
|
-
if (!this.dbList[dbName]) {
|
|
123
|
-
this.dbList[dbName] = new this.BetterSqlite3(this.getStoreName(dbName), { fileMustExist: false });
|
|
124
|
-
this.dbList[dbName].pragma('journal_mode = WAL');
|
|
117
|
+
`);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
initDB(dbName) {
|
|
122
|
+
if (!this.dbList[dbName]) {
|
|
123
|
+
this.dbList[dbName] = new this.BetterSqlite3(this.getStoreName(dbName), { fileMustExist: false });
|
|
124
|
+
this.dbList[dbName].pragma('journal_mode = WAL');
|
|
125
125
|
this.dbList[dbName].exec(`
|
|
126
126
|
CREATE TABLE IF NOT EXISTS DUAL ( ______id INTEGER NOT NULL, PRIMARY KEY ( ______id ));
|
|
127
127
|
DELETE FROM DUAL;
|
|
@@ -131,56 +131,55 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
|
|
|
131
131
|
______version text NOT NULL,
|
|
132
132
|
PRIMARY KEY ( ______tableName )
|
|
133
133
|
);
|
|
134
|
-
`);
|
|
135
|
-
this.dbList[dbName].function('UUID_SHORT', { deterministic: false }, () => snowflake.generate());
|
|
136
|
-
this.dbList[dbName].function('UUID', { deterministic: false }, () => snowflake.generate());
|
|
137
|
-
this.dbList[dbName].function('TIME_TO_SEC', { deterministic: true }, (time
|
|
138
|
-
this.dbList[dbName].function('IF', { deterministic: true }, (condition
|
|
139
|
-
this.dbList[dbName].function('RIGHT', { deterministic: true }, (src
|
|
140
|
-
this.dbList[dbName].function('LEFT', { deterministic: true }, (str
|
|
141
|
-
this.dbList[dbName].function('NOW', { deterministic: false }, () => new Date().toISOString().slice(0, 19).replace('T', ' '));
|
|
142
|
-
this.dbList[dbName].function('CURDATE', { deterministic: false }, () => new Date().toISOString().split('T')[0]);
|
|
143
|
-
this.dbList[dbName].function('DATE_FORMAT', { deterministic: true }, (dateStr
|
|
144
|
-
const date = new Date(dateStr);
|
|
145
|
-
return format
|
|
146
|
-
.replace('%Y', date.getFullYear().toString())
|
|
147
|
-
.replace('%m', (date.getMonth() + 1).toString().padStart(2, '0'))
|
|
148
|
-
.replace('%d', date.getDate().toString().padStart(2, '0'))
|
|
149
|
-
.replace('%H', date.getHours().toString().padStart(2, '0'))
|
|
150
|
-
.replace('%i', date.getMinutes().toString().padStart(2, '0'))
|
|
151
|
-
.replace('%s', date.getSeconds().toString().padStart(2, '0'));
|
|
152
|
-
});
|
|
153
|
-
this.dbList[dbName].function('RAND', { deterministic: false }, () => Math.random());
|
|
154
|
-
this.dbList[dbName].function('UNIX_TIMESTAMP', { deterministic: false },
|
|
155
|
-
(dateStr
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.
|
|
171
|
-
this.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
134
|
+
`);
|
|
135
|
+
this.dbList[dbName].function('UUID_SHORT', { deterministic: false }, () => snowflake.generate());
|
|
136
|
+
this.dbList[dbName].function('UUID', { deterministic: false }, () => snowflake.generate());
|
|
137
|
+
this.dbList[dbName].function('TIME_TO_SEC', { deterministic: true }, (time) => time.split(':').map((v, i) => parseInt(v) * (i === 0 ? 360 : i === 1 ? 60 : 0)).reduce((a, b) => a + b, 0));
|
|
138
|
+
this.dbList[dbName].function('IF', { deterministic: true }, (condition, v1, v2) => condition ? v1 : v2);
|
|
139
|
+
this.dbList[dbName].function('RIGHT', { deterministic: true }, (src, p) => src.slice(p * -1));
|
|
140
|
+
this.dbList[dbName].function('LEFT', { deterministic: true }, (str, len) => str?.substring(0, len) || null);
|
|
141
|
+
this.dbList[dbName].function('NOW', { deterministic: false }, () => new Date().toISOString().slice(0, 19).replace('T', ' '));
|
|
142
|
+
this.dbList[dbName].function('CURDATE', { deterministic: false }, () => new Date().toISOString().split('T')[0]);
|
|
143
|
+
this.dbList[dbName].function('DATE_FORMAT', { deterministic: true }, (dateStr, format) => {
|
|
144
|
+
const date = new Date(dateStr);
|
|
145
|
+
return format
|
|
146
|
+
.replace('%Y', date.getFullYear().toString())
|
|
147
|
+
.replace('%m', (date.getMonth() + 1).toString().padStart(2, '0'))
|
|
148
|
+
.replace('%d', date.getDate().toString().padStart(2, '0'))
|
|
149
|
+
.replace('%H', date.getHours().toString().padStart(2, '0'))
|
|
150
|
+
.replace('%i', date.getMinutes().toString().padStart(2, '0'))
|
|
151
|
+
.replace('%s', date.getSeconds().toString().padStart(2, '0'));
|
|
152
|
+
});
|
|
153
|
+
this.dbList[dbName].function('RAND', { deterministic: false }, () => Math.random());
|
|
154
|
+
this.dbList[dbName].function('UNIX_TIMESTAMP', { deterministic: false }, (dateStr) => dateStr
|
|
155
|
+
? Math.floor(new Date(dateStr).getTime() / 1000)
|
|
156
|
+
: Math.floor(Date.now() / 1000));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async export(dbName, exportPath) {
|
|
160
|
+
await this.dbList[dbName].backup(exportPath);
|
|
161
|
+
}
|
|
162
|
+
restore(dbName, importPath) {
|
|
163
|
+
if (this.dbList[dbName]) {
|
|
164
|
+
this.dbList[dbName].close();
|
|
165
|
+
this.dbList[dbName] = null;
|
|
166
|
+
}
|
|
167
|
+
const nn = this.getStoreName(dbName);
|
|
168
|
+
this.cpSync(nn, this.getBackName(dbName));
|
|
169
|
+
this.cpSync(importPath, nn, { force: true });
|
|
170
|
+
this.setMod(nn);
|
|
171
|
+
this.initDB(dbName);
|
|
172
|
+
}
|
|
173
|
+
close(dbName) {
|
|
174
|
+
if (dbName) {
|
|
175
|
+
this.dbList[dbName]?.close();
|
|
176
|
+
this.dbList[dbName] = null;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
for (const db of Object.values(this.dbList)) {
|
|
180
|
+
db?.close();
|
|
181
|
+
}
|
|
182
|
+
this.dbList = {};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
package/string.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通过uri获取key
|
|
3
|
+
* @param uri
|
|
4
|
+
*/
|
|
5
|
+
export declare const getPicKey: (uri: string) => string;
|
|
6
|
+
export declare const emptyString: (source: any, skipEmptyString?: boolean) => boolean;
|
|
7
|
+
export declare const notEmptyString: (source: any, skipEmptyString?: boolean) => boolean;
|
|
8
|
+
export declare const safeString: (source?: string) => string;
|
|
9
|
+
export declare const trimObject: <T>(data: any) => T;
|
|
10
|
+
export declare const randomNumber: (len: number) => string;
|
|
11
|
+
export declare const randomString: (len: number) => string;
|
|
12
|
+
export declare const randomString2: (len: number) => string;
|
|
13
|
+
export declare const randomString3: (len: number) => string;
|
|
14
|
+
export declare const buildWxStr: (data: {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
}, maxLabelLength: number, ...titles: string[]) => string;
|
|
17
|
+
export declare const replaceChineseCode: (str: string) => string;
|
package/string.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通过uri获取key
|
|
3
|
+
* @param uri
|
|
4
|
+
*/
|
|
5
|
+
export const getPicKey = (uri) => {
|
|
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
|
+
export const emptyString = (source, skipEmptyString = true) => {
|
|
13
|
+
return (source === null ||
|
|
14
|
+
source === undefined ||
|
|
15
|
+
(skipEmptyString === true && (source === '' || `${source}`.replace(/\s/g, '') === '')));
|
|
16
|
+
};
|
|
17
|
+
export const notEmptyString = (source, skipEmptyString = true) => {
|
|
18
|
+
return emptyString(source, skipEmptyString) === false;
|
|
19
|
+
};
|
|
20
|
+
export const safeString = (source) => {
|
|
21
|
+
if (source) {
|
|
22
|
+
return `${source}`.replace(/'/g, '');
|
|
23
|
+
}
|
|
24
|
+
return '';
|
|
25
|
+
};
|
|
26
|
+
export const trimObject = (data) => {
|
|
27
|
+
if (data) {
|
|
28
|
+
for (const k in data) {
|
|
29
|
+
if (typeof data[k] === 'string') {
|
|
30
|
+
data[k] = data[k].trim();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
export const randomNumber = (len) => {
|
|
37
|
+
return `${parseInt(`${(Math.random() * 9 + 1) * Math.pow(10, (len - 1))}`, 10)}`;
|
|
38
|
+
};
|
|
39
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
40
|
+
const charLen = chars.length;
|
|
41
|
+
export const randomString = (len) => {
|
|
42
|
+
return Array.from(new Array(len)).map(() => chars.charAt(Math.floor(Math.random() * charLen))).join('');
|
|
43
|
+
};
|
|
44
|
+
const chars2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
45
|
+
const charLen2 = chars2.length;
|
|
46
|
+
export const randomString2 = (len) => {
|
|
47
|
+
return Array.from(new Array(len)).map(() => chars2.charAt(Math.floor(Math.random() * charLen2))).join('');
|
|
48
|
+
};
|
|
49
|
+
const chars3 = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
50
|
+
const charLen3 = chars3.length;
|
|
51
|
+
export const randomString3 = (len) => {
|
|
52
|
+
return Array.from(new Array(len)).map(() => chars3.charAt(Math.floor(Math.random() * charLen3))).join('');
|
|
53
|
+
};
|
|
54
|
+
export const buildWxStr = (data, maxLabelLength, ...titles) => {
|
|
55
|
+
let str = titles.join('\r\n');
|
|
56
|
+
str += '\r\n\r\n';
|
|
57
|
+
const items = new Array();
|
|
58
|
+
// const maxLength = maxLabelLength * 2;
|
|
59
|
+
for (const [key, value] of Object.entries(data)) {
|
|
60
|
+
if (notEmptyString(value)) {
|
|
61
|
+
const len = maxLabelLength - key.length;
|
|
62
|
+
items.push(`${key}:${''.padEnd(len * 3 + (len > 0 ? 1 : 0), ' ')}${value}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
str += items.join('\r\n');
|
|
66
|
+
return str;
|
|
67
|
+
};
|
|
68
|
+
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;
|
|
69
|
+
const table = {
|
|
70
|
+
'!': '!',
|
|
71
|
+
'¥': '$',
|
|
72
|
+
'…': '.',
|
|
73
|
+
'(': '(',
|
|
74
|
+
')': ')',
|
|
75
|
+
'《': '<',
|
|
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
|
+
export const replaceChineseCode = (str) => {
|
|
104
|
+
return str.replace(chinese, (a) => table[a] || '');
|
|
105
|
+
};
|
package/test-mysql.d.ts
ADDED
package/test-mysql.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Field, SqlType } from 'baja-lite-field';
|
|
11
|
+
import 'reflect-metadata';
|
|
12
|
+
import { Boot } from './boot.js';
|
|
13
|
+
import { ColumnMode, DB, SelectResult, SqlService } from './sql.js';
|
|
14
|
+
class BaseAuditUser {
|
|
15
|
+
}
|
|
16
|
+
__decorate([
|
|
17
|
+
Field({ type: SqlType.varchar, length: 32, id: true, notNull: true, uuidShort: true }),
|
|
18
|
+
__metadata("design:type", String)
|
|
19
|
+
], BaseAuditUser.prototype, "auditId", void 0);
|
|
20
|
+
__decorate([
|
|
21
|
+
Field({ type: SqlType.varchar, length: 32, comment: '密码' }),
|
|
22
|
+
__metadata("design:type", String)
|
|
23
|
+
], BaseAuditUser.prototype, "password", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
Field({ type: SqlType.varchar, length: 255, comment: '省' }),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], BaseAuditUser.prototype, "userProvinceCode", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
Field({ type: SqlType.varchar, length: 255, comment: '省' }),
|
|
30
|
+
__metadata("design:type", String)
|
|
31
|
+
], BaseAuditUser.prototype, "userProvince", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
Field({ type: SqlType.varchar, length: 32, comment: '显示名称' }),
|
|
34
|
+
__metadata("design:type", String)
|
|
35
|
+
], BaseAuditUser.prototype, "labelName", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
Field({ type: SqlType.varchar, length: 32, comment: '备注名称' }),
|
|
38
|
+
__metadata("design:type", String)
|
|
39
|
+
], BaseAuditUser.prototype, "remarkName", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
Field({ type: SqlType.varchar, length: 32, comment: '初始密码' }),
|
|
42
|
+
__metadata("design:type", String)
|
|
43
|
+
], BaseAuditUser.prototype, "upassword", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
Field({ type: SqlType.char, length: 1, def: 0, comment: '是否中心' }),
|
|
46
|
+
__metadata("design:type", String)
|
|
47
|
+
], BaseAuditUser.prototype, "baseType", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
Field({ type: SqlType.varchar, length: 32 }),
|
|
50
|
+
__metadata("design:type", String)
|
|
51
|
+
], BaseAuditUser.prototype, "userId", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
Field({ type: SqlType.varchar, length: 32 }),
|
|
54
|
+
__metadata("design:type", String)
|
|
55
|
+
], BaseAuditUser.prototype, "companyId", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
Field({ type: SqlType.varchar, length: 32 }),
|
|
58
|
+
__metadata("design:type", String)
|
|
59
|
+
], BaseAuditUser.prototype, "username", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
Field({ type: SqlType.char, length: 1, def: 0, comment: '状态' }),
|
|
62
|
+
__metadata("design:type", String)
|
|
63
|
+
], BaseAuditUser.prototype, "userStatus", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
Field({ type: SqlType.char, length: 1, def: 0, comment: '账户分组' }),
|
|
66
|
+
__metadata("design:type", String)
|
|
67
|
+
], BaseAuditUser.prototype, "groupId", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
Field({ type: SqlType.varchar, length: 10 }),
|
|
70
|
+
__metadata("design:type", String)
|
|
71
|
+
], BaseAuditUser.prototype, "startDate", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
Field({ type: SqlType.varchar, length: 10 }),
|
|
74
|
+
__metadata("design:type", String)
|
|
75
|
+
], BaseAuditUser.prototype, "endDate", void 0);
|
|
76
|
+
let BaseAuditUserService = class BaseAuditUserService extends SqlService {
|
|
77
|
+
};
|
|
78
|
+
BaseAuditUserService = __decorate([
|
|
79
|
+
DB({ tableName: 'base_audit_user', clz: BaseAuditUser })
|
|
80
|
+
], BaseAuditUserService);
|
|
81
|
+
export async function go2() {
|
|
82
|
+
await Boot({
|
|
83
|
+
Mysql: {
|
|
84
|
+
host: '127.0.0.1',
|
|
85
|
+
port: 3306,
|
|
86
|
+
user: 'root',
|
|
87
|
+
password: 'abcd1234',
|
|
88
|
+
// 数据库名
|
|
89
|
+
database: 'sportevent',
|
|
90
|
+
debug: false
|
|
91
|
+
},
|
|
92
|
+
log: 'trace',
|
|
93
|
+
columnMode: ColumnMode.HUMP,
|
|
94
|
+
sqlDir: 'E:/pro/my-sdk/baja-lite/xml',
|
|
95
|
+
sqlMap: {
|
|
96
|
+
['test.test']: `
|
|
97
|
+
SELECT * FROM base_user {{#realname}} WHERE realname LIKE CONCAT(:realname, '%') {{/realname}};
|
|
98
|
+
SELECT * FROM base_user {{#realname}} WHERE realname LIKE CONCAT(:realname, '%') {{/realname}};
|
|
99
|
+
`
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const service = new BaseAuditUserService();
|
|
103
|
+
const rt = await service.stream().eq('auditId', '100987125344341382').select('labelName').where('audit_id > 0').excuteSelect({ selectResult: SelectResult.R_C_Assert });
|
|
104
|
+
console.log(rt);
|
|
105
|
+
// const list = await service.transaction<number>({
|
|
106
|
+
// fn: async conn => {
|
|
107
|
+
// await service.stream().eq('baseType', '0').in('auditId', ['162400829591265280', '162201628882247680']).excuteSelect();
|
|
108
|
+
// const data = await service.stream().in('auditId', ['162400829591265280', '162201628882247680']).update('labelName', '333').excuteUpdate({ conn });
|
|
109
|
+
// return data;
|
|
110
|
+
// }
|
|
111
|
+
// });
|
|
112
|
+
// console.log(11, list);
|
|
113
|
+
}
|
|
114
|
+
go2();
|