baja-lite 1.3.25 → 1.3.27
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 +4 -0
- package/.vscode/settings.json +8 -0
- package/ci.js +29 -0
- package/package-cjs.json +17 -0
- package/package.json +2 -2
- package/{boot-remote.js → src/boot-remote.ts} +7 -6
- package/{boot.js → src/boot.ts} +38 -31
- package/{code.js → src/code.ts} +66 -71
- package/{convert-xml.js → src/convert-xml.ts} +155 -105
- package/src/enum.ts +71 -0
- package/src/error.ts +11 -0
- package/src/fn.ts +295 -0
- package/{index.d.ts → src/index.ts} +12 -11
- package/{list.js → src/list.ts} +9 -8
- package/src/math.ts +405 -0
- package/src/object.ts +247 -0
- package/{snowflake.js → src/snowflake.ts} +52 -33
- package/src/sql.ts +5023 -0
- package/{sqlite.js → src/sqlite.ts} +52 -53
- package/src/string.ts +111 -0
- package/src/test-mysql.ts +144 -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} +1 -1
- package/{test.js → src/test.ts} +3 -2
- package/src/wx/base.ts +76 -0
- package/src/wx/mini.ts +147 -0
- package/src/wx/organ.ts +290 -0
- package/{wx/types.d.ts → src/wx/types.ts} +10 -21
- package/tsconfig.cjs.json +42 -0
- package/tsconfig.json +44 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/xml/event-report.xml +13 -0
- package/yarn.lock +1757 -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/enum.d.ts +0 -18
- package/enum.js +0 -59
- package/error.d.ts +0 -5
- package/error.js +0 -13
- package/fn.d.ts +0 -128
- package/fn.js +0 -172
- package/index.js +0 -11
- package/list.d.ts +0 -10
- package/math.d.ts +0 -83
- package/math.js +0 -451
- package/object.d.ts +0 -83
- package/object.js +0 -221
- package/snowflake.d.ts +0 -12
- package/sql.d.ts +0 -1788
- package/sql.js +0 -4765
- 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 -109
- 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
- /package/{wx.d.ts → src/wx.ts} +0 -0
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
import { extensionCodec, logger } from './sql.js';
|
|
1
|
+
import { SqliteRemoteInterface, extensionCodec, logger } from './sql.js';
|
|
2
2
|
import Sqlstring from 'sqlstring';
|
|
3
3
|
import { encode, decode } from "@msgpack/msgpack";
|
|
4
|
-
export class SqliteRemoteClass {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
|
|
5
|
+
private dbList: Record<string, any> = {};
|
|
6
|
+
/** 原始存放路径 */
|
|
7
|
+
abstract getStoreName(dbName: string): string;
|
|
8
|
+
/** 导入时,备份源文件路径 */
|
|
9
|
+
abstract getBackName(dbName: string): string;
|
|
10
|
+
abstract BetterSqlite3: any;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/** 实现复制 */
|
|
14
|
+
abstract cpSync(from: string, to: string, option?: { force: true }): void;
|
|
15
|
+
/**
|
|
16
|
+
* 设置可执行权限
|
|
17
|
+
```
|
|
18
|
+
const fd = openSync(dbPath, 1);
|
|
19
|
+
fchmodSync(fd, 777);
|
|
20
|
+
closeSync(fd);
|
|
21
|
+
```
|
|
22
|
+
*/
|
|
23
|
+
abstract setMod(name: string): void;
|
|
24
|
+
abstract trace: boolean;
|
|
25
|
+
async execute(inData: Uint8Array): Promise<Uint8Array> {
|
|
26
|
+
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
10
27
|
logger.debug(sql, params ?? '');
|
|
11
28
|
try {
|
|
12
|
-
if (!sql) {
|
|
13
|
-
return encode({ affectedRows: 0, insertId: 0n }, { extensionCodec });
|
|
14
|
-
}
|
|
15
|
-
;
|
|
29
|
+
if (!sql) { return encode({ affectedRows: 0, insertId: 0n }, { extensionCodec }); };
|
|
16
30
|
if (this.trace) {
|
|
17
|
-
logger.trace(Sqlstring.format(sql
|
|
31
|
+
logger.trace(Sqlstring.format(sql!, params));
|
|
18
32
|
}
|
|
19
33
|
const result = this.dbList[dbName].prepare(sql).run(params ?? {});
|
|
20
34
|
if (this.trace) {
|
|
@@ -22,8 +36,7 @@ export class SqliteRemoteClass {
|
|
|
22
36
|
}
|
|
23
37
|
const { changes, lastInsertRowid } = result;
|
|
24
38
|
return encode({ affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n }, { extensionCodec });
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
39
|
+
} catch (error) {
|
|
27
40
|
logger.error(`
|
|
28
41
|
error: ${error},
|
|
29
42
|
sql: ${sql},
|
|
@@ -32,21 +45,17 @@ export class SqliteRemoteClass {
|
|
|
32
45
|
throw error;
|
|
33
46
|
}
|
|
34
47
|
}
|
|
35
|
-
async pluck(inData) {
|
|
36
|
-
const [dbName, sql, params] = decode(inData);
|
|
48
|
+
async pluck(inData: Uint8Array): Promise<Uint8Array> {
|
|
49
|
+
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
37
50
|
logger.debug(sql, params ?? '');
|
|
38
51
|
try {
|
|
39
52
|
logger.debug(sql, params ?? '');
|
|
40
|
-
if (!sql) {
|
|
41
|
-
return encode(null);
|
|
42
|
-
}
|
|
43
|
-
;
|
|
53
|
+
if (!sql) { return encode(null) };
|
|
44
54
|
if (this.trace) {
|
|
45
|
-
logger.trace(Sqlstring.format(sql
|
|
55
|
+
logger.trace(Sqlstring.format(sql!, params));
|
|
46
56
|
}
|
|
47
57
|
return encode(this.dbList[dbName].prepare(sql).pluck().get(params ?? {}), { extensionCodec });
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
58
|
+
} catch (error) {
|
|
50
59
|
logger.error(`
|
|
51
60
|
error: ${error},
|
|
52
61
|
sql: ${sql},
|
|
@@ -55,16 +64,15 @@ export class SqliteRemoteClass {
|
|
|
55
64
|
throw error;
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
|
-
async get(inData) {
|
|
59
|
-
const [dbName, sql, params] = decode(inData);
|
|
67
|
+
async get(inData: Uint8Array): Promise<Uint8Array> {
|
|
68
|
+
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
60
69
|
logger.debug(sql, params ?? '');
|
|
61
70
|
try {
|
|
62
71
|
if (this.trace) {
|
|
63
|
-
logger.trace(Sqlstring.format(sql
|
|
72
|
+
logger.trace(Sqlstring.format(sql!, params));
|
|
64
73
|
}
|
|
65
74
|
return encode(this.dbList[dbName].prepare(sql).get(params ?? {}), { extensionCodec });
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
75
|
+
} catch (error) {
|
|
68
76
|
logger.error(`
|
|
69
77
|
error: ${error},
|
|
70
78
|
sql: ${sql},
|
|
@@ -73,20 +81,16 @@ export class SqliteRemoteClass {
|
|
|
73
81
|
throw error;
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
|
-
async raw(inData) {
|
|
77
|
-
const [dbName, sql, params] = decode(inData);
|
|
84
|
+
async raw(inData: Uint8Array): Promise<Uint8Array> {
|
|
85
|
+
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
78
86
|
logger.debug(sql, params ?? '');
|
|
79
87
|
try {
|
|
80
|
-
if (!sql) {
|
|
81
|
-
return encode([]);
|
|
82
|
-
}
|
|
83
|
-
;
|
|
88
|
+
if (!sql) { return encode([]); };
|
|
84
89
|
if (this.trace) {
|
|
85
|
-
logger.trace(Sqlstring.format(sql
|
|
90
|
+
logger.trace(Sqlstring.format(sql!, params));
|
|
86
91
|
}
|
|
87
92
|
return encode(this.dbList[dbName].prepare(sql).raw().all(params ?? {}), { extensionCodec });
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
93
|
+
} catch (error) {
|
|
90
94
|
logger.error(`
|
|
91
95
|
error: ${error},
|
|
92
96
|
sql: ${sql},
|
|
@@ -95,20 +99,16 @@ export class SqliteRemoteClass {
|
|
|
95
99
|
throw error;
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
|
-
async query(inData) {
|
|
99
|
-
const [dbName, sql, params] = decode(inData);
|
|
102
|
+
async query(inData: Uint8Array): Promise<Uint8Array> {
|
|
103
|
+
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
100
104
|
logger.debug(sql, params ?? '');
|
|
101
105
|
try {
|
|
102
|
-
if (!sql) {
|
|
103
|
-
encode([]);
|
|
104
|
-
}
|
|
105
|
-
;
|
|
106
|
+
if (!sql) { encode([]); };
|
|
106
107
|
if (this.trace) {
|
|
107
|
-
logger.trace(Sqlstring.format(sql
|
|
108
|
+
logger.trace(Sqlstring.format(sql!, params));
|
|
108
109
|
}
|
|
109
110
|
return encode(this.dbList[dbName].prepare(sql).all(params ?? {}), { extensionCodec });
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
111
|
+
} catch (error) {
|
|
112
112
|
logger.error(`
|
|
113
113
|
error: ${error},
|
|
114
114
|
sql: ${sql},
|
|
@@ -117,7 +117,7 @@ export class SqliteRemoteClass {
|
|
|
117
117
|
throw error;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
initDB(dbName) {
|
|
120
|
+
initDB(dbName: string) {
|
|
121
121
|
if (!this.dbList[dbName]) {
|
|
122
122
|
this.dbList[dbName] = new this.BetterSqlite3(this.getStoreName(dbName), { fileMustExist: false });
|
|
123
123
|
this.dbList[dbName].pragma('journal_mode = WAL');
|
|
@@ -133,10 +133,10 @@ export class SqliteRemoteClass {
|
|
|
133
133
|
`);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
-
async export(dbName, exportPath) {
|
|
136
|
+
async export(dbName: string, exportPath: string): Promise<void> {
|
|
137
137
|
await this.dbList[dbName].backup(exportPath);
|
|
138
138
|
}
|
|
139
|
-
restore(dbName, importPath) {
|
|
139
|
+
restore(dbName: string, importPath: string) {
|
|
140
140
|
if (this.dbList[dbName]) {
|
|
141
141
|
this.dbList[dbName].close();
|
|
142
142
|
this.dbList[dbName] = null;
|
|
@@ -147,16 +147,15 @@ export class SqliteRemoteClass {
|
|
|
147
147
|
this.setMod(nn);
|
|
148
148
|
this.initDB(dbName);
|
|
149
149
|
}
|
|
150
|
-
close(dbName) {
|
|
150
|
+
close(dbName?: string) {
|
|
151
151
|
if (dbName) {
|
|
152
152
|
this.dbList[dbName]?.close();
|
|
153
153
|
this.dbList[dbName] = null;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
154
|
+
} else {
|
|
156
155
|
for (const db of Object.values(this.dbList)) {
|
|
157
156
|
db?.close();
|
|
158
157
|
}
|
|
159
158
|
this.dbList = {};
|
|
160
159
|
}
|
|
161
160
|
}
|
|
162
|
-
}
|
|
161
|
+
}
|
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,144 @@
|
|
|
1
|
+
import { Field, SqlType } from 'baja-lite-field';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
import { Boot } from './boot.js';
|
|
4
|
+
import { ColumnMode, DB, 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/baja-lite/xml',
|
|
129
|
+
sqlMap: {
|
|
130
|
+
['test.test']: `SELECT * FROM cp_user {{#username}} WHERE username = :username {{/username}}`
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const service = new BaseAuditUserService();
|
|
134
|
+
const list = await service.transaction<number>({
|
|
135
|
+
fn: async conn => {
|
|
136
|
+
await service.stream().eq('baseType', '0').in('auditId', ['162400829591265280', '162201628882247680']).excuteSelect();
|
|
137
|
+
const data = await service.stream().in('auditId', ['162400829591265280', '162201628882247680']).update('labelName', '333').excuteUpdate({ conn });
|
|
138
|
+
|
|
139
|
+
return data;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
console.log(11, list);
|
|
143
|
+
}
|
|
144
|
+
go2();
|
|
@@ -1,91 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// matchInfo: { reportType: 'yyyy', id: '11' }
|
|
82
|
-
// },
|
|
83
|
-
// // mapper: [
|
|
84
|
-
// // ['site', ['info', 'bSist'], 989],
|
|
85
|
-
// // ['site', ['info2', 'bSist'], 33],
|
|
86
|
-
// // ['site', ['Bsite'], 0]
|
|
87
|
-
// // ]
|
|
88
|
-
// });
|
|
89
|
-
// console.log(data);
|
|
90
|
-
}
|
|
91
|
-
go2();
|
|
1
|
+
import { DBType, 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 AmaFuck2 {
|
|
6
|
+
@Field({ type: SqlType.int, length: 200, id: true, uuid: true })
|
|
7
|
+
userid?: number;
|
|
8
|
+
@Field({ type: SqlType.varchar, length: 200, def: '333' })
|
|
9
|
+
username?: string;
|
|
10
|
+
@Field({ type: SqlType.varchar, length: 200 })
|
|
11
|
+
pwd?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@DB({
|
|
15
|
+
tableName: 'nfc_user', clz: AmaFuck2, dbType: DBType.Postgresql
|
|
16
|
+
})
|
|
17
|
+
class AmaService2 extends SqlService<AmaFuck2> {
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// interface Menu {
|
|
22
|
+
// resourceid: string;
|
|
23
|
+
// resourcepid: string;
|
|
24
|
+
// resourcename: string;
|
|
25
|
+
// children: Menu[];
|
|
26
|
+
// }
|
|
27
|
+
|
|
28
|
+
export async function go2() {
|
|
29
|
+
await Boot({
|
|
30
|
+
Postgresql: {
|
|
31
|
+
database: 'nfc',
|
|
32
|
+
user: 'postgres',
|
|
33
|
+
password: 'abcd1234',
|
|
34
|
+
port: 5432,
|
|
35
|
+
host: '127.0.0.1'
|
|
36
|
+
},
|
|
37
|
+
log: 'info',
|
|
38
|
+
columnMode: ColumnMode.HUMP,
|
|
39
|
+
sqlDir: 'E:/pro/baja-lite/xml',
|
|
40
|
+
sqlMap: {
|
|
41
|
+
['test.test']: `SELECT * FROM nfc_user {{#username}} WHERE username = :username {{/username}}`
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const service = new AmaService2();
|
|
45
|
+
await service.transaction<number>({
|
|
46
|
+
fn: async conn => {
|
|
47
|
+
const rt5 = await service.select<{ username: string }>({
|
|
48
|
+
sqlId: 'test.test',
|
|
49
|
+
params: { username: '1111' },
|
|
50
|
+
selectResult: SelectResult.RS_CS,
|
|
51
|
+
conn
|
|
52
|
+
})
|
|
53
|
+
console.log(55, rt5.length);
|
|
54
|
+
await service.insert({
|
|
55
|
+
data: {
|
|
56
|
+
userid: 22,
|
|
57
|
+
username: '222',
|
|
58
|
+
pwd: '333'
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// const data = await service.select<Menu>({
|
|
66
|
+
// sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
|
|
67
|
+
// params: {
|
|
68
|
+
// site: '1234',
|
|
69
|
+
// matchInfo: { reportType: 'yyyy', id: '11' }
|
|
70
|
+
// },
|
|
71
|
+
// // mapper: [
|
|
72
|
+
// // ['site', ['info', 'bSist'], 989],
|
|
73
|
+
// // ['site', ['info2', 'bSist'], 33],
|
|
74
|
+
// // ['site', ['Bsite'], 0]
|
|
75
|
+
// // ]
|
|
76
|
+
// });
|
|
77
|
+
// console.log(data);
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
go2();
|