baja-lite 1.6.2 → 1.6.4
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/.eslintignore +7 -0
- package/.eslintrc.cjs +89 -0
- package/.prettierrc +7 -0
- package/.vscode/settings.json +9 -0
- package/ci.js +33 -0
- package/package-cjs.json +17 -0
- package/package.json +80 -80
- package/pnpm-lock.yaml +2840 -0
- package/pnpm-workspace.yaml +2 -0
- package/{boot-remote.js → src/boot-remote.ts} +64 -63
- package/{boot.js → src/boot.ts} +170 -163
- package/{code.js → src/code.ts} +526 -517
- package/{convert-xml.js → src/convert-xml.ts} +460 -410
- package/src/error.ts +11 -0
- package/src/event.ts +34 -0
- package/src/fn.ts +295 -0
- package/{index.d.ts → src/index.ts} +11 -10
- package/src/math.ts +405 -0
- package/src/object.ts +342 -0
- package/{snowflake.js → src/snowflake.ts} +127 -108
- package/src/sql.ts +5529 -0
- package/{sqlite.js → src/sqlite.ts} +157 -156
- package/src/string.ts +111 -0
- package/src/test-mysql.ts +148 -0
- package/{test-postgresql.js → src/test-postgresql.ts} +80 -91
- package/{test-sqlite.js → src/test-sqlite.ts} +80 -90
- package/{test-xml.js → src/test-xml.ts} +70 -70
- package/{test.js → src/test.ts} +3 -2
- package/src/wx/base.ts +77 -0
- package/src/wx/mini.ts +147 -0
- package/src/wx/organ.ts +290 -0
- package/{wx/types.d.ts → src/wx/types.ts} +549 -560
- package/{wx.d.ts → src/wx.ts} +3 -3
- package/tsconfig.cjs.json +42 -0
- package/tsconfig.json +44 -0
- package/xml/event-report.xml +13 -0
- package/yarn.lock +1977 -0
- package/boot-remote.d.ts +0 -2
- package/boot.d.ts +0 -2
- package/code.d.ts +0 -2
- package/convert-xml.d.ts +0 -10
- package/error.d.ts +0 -5
- package/error.js +0 -13
- package/event.d.ts +0 -10
- package/event.js +0 -38
- package/fn.d.ts +0 -128
- package/fn.js +0 -172
- package/index.js +0 -10
- package/math.d.ts +0 -83
- package/math.js +0 -451
- package/object.d.ts +0 -126
- package/object.js +0 -321
- package/snowflake.d.ts +0 -12
- package/sql.d.ts +0 -2148
- package/sql.js +0 -5372
- package/sqlite.d.ts +0 -32
- package/string.d.ts +0 -17
- package/string.js +0 -105
- package/test-mysql.d.ts +0 -2
- package/test-mysql.js +0 -114
- package/test-postgresql.d.ts +0 -2
- package/test-sqlite.d.ts +0 -1
- package/test-xml.d.ts +0 -1
- package/test.d.ts +0 -1
- package/wx/base.d.ts +0 -11
- package/wx/base.js +0 -78
- package/wx/mini.d.ts +0 -52
- package/wx/mini.js +0 -112
- package/wx/organ.d.ts +0 -65
- package/wx/organ.js +0 -171
- package/wx/types.js +0 -1
- package/wx.js +0 -3
- /package/{README.md → Readme.md} +0 -0
|
@@ -1,127 +1,127 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import { decode, encode } from "@msgpack/msgpack";
|
|
2
|
+
import Sqlstring from 'sqlstring';
|
|
3
|
+
import { snowflake } from './snowflake.js';
|
|
4
|
+
import { SqliteRemoteInterface, extensionCodec, logger } from './sql.js';
|
|
5
|
+
export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
|
|
6
|
+
private dbList: Record<string, any> = {};
|
|
7
|
+
/** 原始存放路径 */
|
|
8
|
+
abstract getStoreName(dbName: string): string;
|
|
9
|
+
/** 导入时,备份源文件路径 */
|
|
10
|
+
abstract getBackName(dbName: string): string;
|
|
11
|
+
abstract BetterSqlite3: any;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/** 实现复制 */
|
|
15
|
+
abstract cpSync(from: string, to: string, option?: { force: true }): void;
|
|
16
|
+
/**
|
|
17
|
+
* 设置可执行权限
|
|
18
|
+
```
|
|
19
|
+
const fd = openSync(dbPath, 1);
|
|
20
|
+
fchmodSync(fd, 777);
|
|
21
|
+
closeSync(fd);
|
|
22
|
+
```
|
|
23
|
+
*/
|
|
24
|
+
abstract setMod(name: string): void;
|
|
25
|
+
abstract trace: boolean;
|
|
26
|
+
async execute(inData: Uint8Array): Promise<Uint8Array> {
|
|
27
|
+
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
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) {
|
|
28
41
|
logger.error(`
|
|
29
42
|
error: ${error},
|
|
30
43
|
sql: ${sql},
|
|
31
44
|
params: ${params}
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
return encode(this.dbList[dbName].prepare(sql).pluck().get(params ?? {}), { extensionCodec });
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
45
|
+
`);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async pluck(inData: Uint8Array): Promise<Uint8Array> {
|
|
50
|
+
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
51
|
+
logger.debug(sql, params ?? '');
|
|
52
|
+
try {
|
|
53
|
+
logger.debug(sql, params ?? '');
|
|
54
|
+
if (!sql) { return encode(null) };
|
|
55
|
+
if (this.trace) {
|
|
56
|
+
logger.trace(Sqlstring.format(sql!, params));
|
|
57
|
+
}
|
|
58
|
+
return encode(this.dbList[dbName].prepare(sql).pluck().get(params ?? {}), { extensionCodec });
|
|
59
|
+
} catch (error) {
|
|
51
60
|
logger.error(`
|
|
52
61
|
error: ${error},
|
|
53
62
|
sql: ${sql},
|
|
54
63
|
params: ${params}
|
|
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
|
|
65
|
-
}
|
|
66
|
-
return encode(this.dbList[dbName].prepare(sql).get(params ?? {}), { extensionCodec });
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
64
|
+
`);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async get(inData: Uint8Array): Promise<Uint8Array> {
|
|
69
|
+
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
70
|
+
logger.debug(sql, params ?? '');
|
|
71
|
+
try {
|
|
72
|
+
if (this.trace) {
|
|
73
|
+
logger.trace(Sqlstring.format(sql!, params));
|
|
74
|
+
}
|
|
75
|
+
return encode(this.dbList[dbName].prepare(sql).get(params ?? {}), { extensionCodec });
|
|
76
|
+
} catch (error) {
|
|
69
77
|
logger.error(`
|
|
70
78
|
error: ${error},
|
|
71
79
|
sql: ${sql},
|
|
72
80
|
params: ${params}
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
return encode(this.dbList[dbName].prepare(sql).raw().all(params ?? {}), { extensionCodec });
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
81
|
+
`);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async raw(inData: Uint8Array): Promise<Uint8Array> {
|
|
86
|
+
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
87
|
+
logger.debug(sql, params ?? '');
|
|
88
|
+
try {
|
|
89
|
+
if (!sql) { return encode([]); };
|
|
90
|
+
if (this.trace) {
|
|
91
|
+
logger.trace(Sqlstring.format(sql!, params));
|
|
92
|
+
}
|
|
93
|
+
return encode(this.dbList[dbName].prepare(sql).raw().all(params ?? {}), { extensionCodec });
|
|
94
|
+
} catch (error) {
|
|
91
95
|
logger.error(`
|
|
92
96
|
error: ${error},
|
|
93
97
|
sql: ${sql},
|
|
94
98
|
params: ${params}
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
return encode(this.dbList[dbName].prepare(sql).all(params ?? {}), { extensionCodec });
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
99
|
+
`);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async query(inData: Uint8Array): Promise<Uint8Array> {
|
|
104
|
+
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
105
|
+
logger.debug(sql, params ?? '');
|
|
106
|
+
try {
|
|
107
|
+
if (!sql) { encode([]); };
|
|
108
|
+
if (this.trace) {
|
|
109
|
+
logger.trace(Sqlstring.format(sql!, params));
|
|
110
|
+
}
|
|
111
|
+
return encode(this.dbList[dbName].prepare(sql).all(params ?? {}), { extensionCodec });
|
|
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: string) {
|
|
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,55 +131,56 @@ export class SqliteRemoteClass {
|
|
|
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) => time.split(':').map((v, i) => parseInt(v) * (i
|
|
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 },
|
|
155
|
-
|
|
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
|
-
}
|
|
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: string) => 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: any, v1: any, v2: any) => condition ? v1 : v2);
|
|
139
|
+
this.dbList[dbName].function('RIGHT', { deterministic: true }, (src: string, p: number) => src.slice(p * -1));
|
|
140
|
+
this.dbList[dbName].function('LEFT', { deterministic: true }, (str: string, len: number) => 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: string, format: string) => {
|
|
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?: string) => dateStr
|
|
156
|
+
? Math.floor(new Date(dateStr).getTime() / 1000)
|
|
157
|
+
: Math.floor(Date.now() / 1000)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async export(dbName: string, exportPath: string): Promise<void> {
|
|
162
|
+
await this.dbList[dbName].backup(exportPath);
|
|
163
|
+
}
|
|
164
|
+
restore(dbName: string, importPath: string) {
|
|
165
|
+
if (this.dbList[dbName]) {
|
|
166
|
+
this.dbList[dbName].close();
|
|
167
|
+
this.dbList[dbName] = null;
|
|
168
|
+
}
|
|
169
|
+
const nn = this.getStoreName(dbName);
|
|
170
|
+
this.cpSync(nn, this.getBackName(dbName));
|
|
171
|
+
this.cpSync(importPath, nn, { force: true });
|
|
172
|
+
this.setMod(nn);
|
|
173
|
+
this.initDB(dbName);
|
|
174
|
+
}
|
|
175
|
+
close(dbName?: string) {
|
|
176
|
+
if (dbName) {
|
|
177
|
+
this.dbList[dbName]?.close();
|
|
178
|
+
this.dbList[dbName] = null;
|
|
179
|
+
} else {
|
|
180
|
+
for (const db of Object.values(this.dbList)) {
|
|
181
|
+
db?.close();
|
|
182
|
+
}
|
|
183
|
+
this.dbList = {};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
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,148 @@
|
|
|
1
|
+
import { Field, SqlType } from 'baja-lite-field';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
import { Boot } from './boot.js';
|
|
4
|
+
import { ColumnMode, DB, SelectResult, SqlService } from './sql.js';
|
|
5
|
+
class BaseAuditUser {
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @type { varchar }
|
|
9
|
+
* @memberof BaseAuditUser
|
|
10
|
+
*/
|
|
11
|
+
@Field({ type: SqlType.varchar, length: 32, id: true, notNull: true, uuidShort: true })
|
|
12
|
+
auditId?: string;
|
|
13
|
+
/**
|
|
14
|
+
* 密码
|
|
15
|
+
* @type { varchar }
|
|
16
|
+
* @memberof BaseAuditUser
|
|
17
|
+
*/
|
|
18
|
+
@Field({ type: SqlType.varchar, length: 32, comment: '密码' })
|
|
19
|
+
password?: string;
|
|
20
|
+
/**
|
|
21
|
+
* 省
|
|
22
|
+
* @type { varchar }
|
|
23
|
+
* @memberof BaseAuditUser
|
|
24
|
+
*/
|
|
25
|
+
@Field({ type: SqlType.varchar, length: 255, comment: '省' })
|
|
26
|
+
userProvinceCode?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 省
|
|
29
|
+
* @type { varchar }
|
|
30
|
+
* @memberof BaseAuditUser
|
|
31
|
+
*/
|
|
32
|
+
@Field({ type: SqlType.varchar, length: 255, comment: '省' })
|
|
33
|
+
userProvince?: string;
|
|
34
|
+
/**
|
|
35
|
+
* 显示名称
|
|
36
|
+
* @type { varchar }
|
|
37
|
+
* @memberof BaseAuditUser
|
|
38
|
+
*/
|
|
39
|
+
@Field({ type: SqlType.varchar, length: 32, comment: '显示名称' })
|
|
40
|
+
labelName?: string;
|
|
41
|
+
/**
|
|
42
|
+
* 备注名称
|
|
43
|
+
* @type { varchar }
|
|
44
|
+
* @memberof BaseAuditUser
|
|
45
|
+
*/
|
|
46
|
+
@Field({ type: SqlType.varchar, length: 32, comment: '备注名称' })
|
|
47
|
+
remarkName?: string;
|
|
48
|
+
/**
|
|
49
|
+
* 初始密码
|
|
50
|
+
* @type { varchar }
|
|
51
|
+
* @memberof BaseAuditUser
|
|
52
|
+
*/
|
|
53
|
+
@Field({ type: SqlType.varchar, length: 32, comment: '初始密码' })
|
|
54
|
+
upassword?: string;
|
|
55
|
+
/**
|
|
56
|
+
* 是否中心
|
|
57
|
+
* @type { char }
|
|
58
|
+
* @memberof BaseAuditUser
|
|
59
|
+
*/
|
|
60
|
+
@Field({ type: SqlType.char, length: 1, def: 0, comment: '是否中心' })
|
|
61
|
+
baseType?: string;
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @type { varchar }
|
|
65
|
+
* @memberof BaseAuditUser
|
|
66
|
+
*/
|
|
67
|
+
@Field({ type: SqlType.varchar, length: 32 })
|
|
68
|
+
userId?: string;
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @type { varchar }
|
|
72
|
+
* @memberof BaseAuditUser
|
|
73
|
+
*/
|
|
74
|
+
@Field({ type: SqlType.varchar, length: 32 })
|
|
75
|
+
companyId?: string;
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @type { varchar }
|
|
79
|
+
* @memberof BaseAuditUser
|
|
80
|
+
*/
|
|
81
|
+
@Field({ type: SqlType.varchar, length: 32 })
|
|
82
|
+
username?: string;
|
|
83
|
+
/**
|
|
84
|
+
* 状态
|
|
85
|
+
* @type { char }
|
|
86
|
+
* @memberof BaseAuditUser
|
|
87
|
+
*/
|
|
88
|
+
@Field({ type: SqlType.char, length: 1, def: 0, comment: '状态' })
|
|
89
|
+
userStatus?: string;
|
|
90
|
+
/**
|
|
91
|
+
* 账户分组
|
|
92
|
+
* @type { char }
|
|
93
|
+
* @memberof BaseAuditUser
|
|
94
|
+
*/
|
|
95
|
+
@Field({ type: SqlType.char, length: 1, def: 0, comment: '账户分组' })
|
|
96
|
+
groupId?: string;
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @type { varchar }
|
|
100
|
+
* @memberof BaseAuditUser
|
|
101
|
+
*/
|
|
102
|
+
@Field({ type: SqlType.varchar, length: 10 })
|
|
103
|
+
startDate?: string;
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* @type { varchar }
|
|
107
|
+
* @memberof BaseAuditUser
|
|
108
|
+
*/
|
|
109
|
+
@Field({ type: SqlType.varchar, length: 10 })
|
|
110
|
+
endDate?: string;
|
|
111
|
+
}
|
|
112
|
+
@DB({ tableName: 'base_audit_user', clz: BaseAuditUser })
|
|
113
|
+
class BaseAuditUserService extends SqlService<BaseAuditUser> {
|
|
114
|
+
}
|
|
115
|
+
export async function go2() {
|
|
116
|
+
await Boot({
|
|
117
|
+
Mysql: {
|
|
118
|
+
host: '127.0.0.1',
|
|
119
|
+
port: 3306,
|
|
120
|
+
user: 'root',
|
|
121
|
+
password: 'abcd1234',
|
|
122
|
+
// 数据库名
|
|
123
|
+
database: 'sportevent',
|
|
124
|
+
debug: false
|
|
125
|
+
},
|
|
126
|
+
log: 'trace',
|
|
127
|
+
columnMode: ColumnMode.HUMP,
|
|
128
|
+
sqlDir: 'E:/pro/my-sdk/baja-lite/xml',
|
|
129
|
+
sqlMap: {
|
|
130
|
+
['test.test']: `
|
|
131
|
+
SELECT * FROM base_user {{#realname}} WHERE realname LIKE CONCAT(:realname, '%') {{/realname}};
|
|
132
|
+
SELECT * FROM base_user {{#realname}} WHERE realname LIKE CONCAT(:realname, '%') {{/realname}};
|
|
133
|
+
`
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const service = new BaseAuditUserService();
|
|
137
|
+
const rt = await service.stream().eq('auditId', '100987125344341382').select('labelName').where('audit_id > 0').excuteSelect({selectResult:SelectResult.R_C_Assert});
|
|
138
|
+
console.log(rt);
|
|
139
|
+
// const list = await service.transaction<number>({
|
|
140
|
+
// fn: async conn => {
|
|
141
|
+
// await service.stream().eq('baseType', '0').in('auditId', ['162400829591265280', '162201628882247680']).excuteSelect();
|
|
142
|
+
// const data = await service.stream().in('auditId', ['162400829591265280', '162201628882247680']).update('labelName', '333').excuteUpdate({ conn });
|
|
143
|
+
// return data;
|
|
144
|
+
// }
|
|
145
|
+
// });
|
|
146
|
+
// console.log(11, list);
|
|
147
|
+
}
|
|
148
|
+
go2();
|