lupine.api 1.1.58 → 1.1.60
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 +3 -3
- package/admin/admin-about.tsx +12 -16
- package/admin/admin-config.tsx +47 -44
- package/admin/admin-css.tsx +3 -3
- package/admin/admin-db.tsx +75 -75
- package/admin/admin-frame-helper.tsx +364 -364
- package/admin/admin-frame.tsx +164 -164
- package/admin/admin-index.tsx +65 -65
- package/admin/admin-login.tsx +111 -111
- package/admin/admin-menu-edit.tsx +637 -637
- package/admin/admin-menu-list.tsx +87 -87
- package/admin/admin-page-edit.tsx +564 -564
- package/admin/admin-page-list.tsx +83 -83
- package/admin/admin-performance.tsx +28 -28
- package/admin/admin-release.tsx +427 -426
- package/admin/admin-resources.tsx +382 -382
- package/admin/admin-shell.tsx +89 -89
- package/admin/admin-table-data.tsx +146 -146
- package/admin/admin-table-list.tsx +230 -230
- package/admin/admin-test-animations.tsx +395 -395
- package/admin/admin-test-component.tsx +823 -808
- package/admin/admin-test-edit.tsx +319 -319
- package/admin/admin-test-themes.tsx +56 -56
- package/admin/admin-tokens.tsx +338 -338
- package/admin/design/admin-design.tsx +174 -174
- package/admin/design/block-grid.tsx +36 -36
- package/admin/design/block-grid1.tsx +21 -21
- package/admin/design/block-paragraph.tsx +19 -19
- package/admin/design/block-title.tsx +19 -19
- package/admin/design/design-block-box.tsx +140 -140
- package/admin/design/drag-data.tsx +24 -24
- package/admin/index.ts +9 -9
- package/admin/package.json +15 -15
- package/admin/tsconfig.json +127 -127
- package/dev/copy-folder.js +32 -32
- package/dev/cp-index-html.js +69 -69
- package/dev/file-utils.js +12 -12
- package/dev/index.js +18 -19
- package/dev/package.json +12 -12
- package/dev/plugin-ifelse.js +168 -168
- package/dev/plugin-ifelse.test.js +37 -37
- package/dev/run-cmd.js +14 -14
- package/dev/send-request.js +12 -12
- package/package.json +55 -55
- package/src/admin-api/admin-api-helper.ts +210 -205
- package/src/admin-api/admin-api.ts +65 -65
- package/src/admin-api/admin-auth.ts +152 -146
- package/src/admin-api/admin-config.ts +94 -84
- package/src/admin-api/admin-csv.ts +94 -94
- package/src/admin-api/admin-db.ts +269 -269
- package/src/admin-api/admin-menu.ts +135 -135
- package/src/admin-api/admin-page.ts +135 -135
- package/src/admin-api/admin-performance.ts +128 -128
- package/src/admin-api/admin-release.ts +706 -700
- package/src/admin-api/admin-resources.ts +318 -318
- package/src/admin-api/admin-token-helper.ts +82 -79
- package/src/admin-api/admin-tokens.ts +90 -90
- package/src/admin-api/index.ts +2 -2
- package/src/admin-api/web-config-api.ts +19 -19
- package/src/api/api-cache.ts +103 -103
- package/src/api/api-helper.ts +44 -44
- package/src/api/api-module.ts +67 -60
- package/src/api/api-router.ts +177 -177
- package/src/api/api-shared-storage.ts +64 -64
- package/src/api/async-storage.ts +5 -5
- package/src/api/debug-service.ts +56 -56
- package/src/api/encode-html.ts +27 -27
- package/src/api/handle-status.ts +75 -75
- package/src/api/index.ts +15 -16
- package/src/api/mini-web-socket.ts +270 -270
- package/src/api/server-content-type.ts +82 -82
- package/src/api/server-render.ts +235 -215
- package/src/api/shell-service.ts +74 -74
- package/src/api/simple-storage.ts +80 -80
- package/src/api/static-server.ts +128 -125
- package/src/api/to-client-delivery.ts +26 -26
- package/src/app/app-cache.ts +55 -55
- package/src/app/app-helper.ts +62 -62
- package/src/app/app-message.ts +109 -109
- package/src/app/app-shared-storage.ts +363 -363
- package/src/app/app-start.ts +136 -136
- package/src/app/cleanup-exit.ts +16 -16
- package/src/app/host-to-path.ts +38 -38
- package/src/app/index.ts +11 -11
- package/src/app/process-dev-requests.ts +130 -130
- package/src/app/web-listener.ts +294 -294
- package/src/app/web-processor.ts +47 -42
- package/src/app/web-server.ts +100 -100
- package/src/common-js/web-env.js +104 -104
- package/src/index.ts +7 -7
- package/src/lang/api-lang-en.ts +26 -26
- package/src/lang/api-lang-zh-cn.ts +27 -27
- package/src/lang/index.ts +2 -2
- package/src/lang/lang-helper.ts +76 -76
- package/src/lang/lang-props.ts +6 -6
- package/src/lib/db/db-helper.ts +23 -23
- package/src/lib/db/db-mysql.ts +249 -250
- package/src/lib/db/db-sqlite.ts +101 -101
- package/src/lib/db/db.spec.ts +28 -28
- package/src/lib/db/db.ts +325 -325
- package/src/lib/db/index.ts +5 -5
- package/src/lib/index.ts +3 -3
- package/src/lib/logger.spec.ts +214 -214
- package/src/lib/logger.ts +281 -281
- package/src/lib/runtime-require.ts +37 -37
- package/src/lib/utils/cookie-util.ts +34 -34
- package/src/lib/utils/crypto.ts +58 -58
- package/src/lib/utils/date-utils.ts +317 -317
- package/src/lib/utils/deep-merge.ts +37 -37
- package/src/lib/utils/delay.ts +12 -12
- package/src/lib/utils/file-setting.ts +55 -55
- package/src/lib/utils/format-bytes.ts +11 -11
- package/src/lib/utils/fs-utils.ts +158 -158
- package/src/lib/utils/get-env.ts +27 -27
- package/src/lib/utils/index.ts +12 -12
- package/src/lib/utils/is-type.ts +48 -48
- package/src/lib/utils/load-env.ts +14 -14
- package/src/lib/utils/pad.ts +6 -6
- package/src/models/api-base.ts +5 -5
- package/src/models/api-module-props.ts +10 -11
- package/src/models/api-router-props.ts +26 -26
- package/src/models/app-cache-props.ts +33 -33
- package/src/models/app-data-props.ts +10 -10
- package/src/models/app-helper-props.ts +6 -6
- package/src/models/app-shared-storage-props.ts +38 -38
- package/src/models/app-start-props.ts +18 -18
- package/src/models/async-storage-props.ts +13 -13
- package/src/models/db-config.ts +30 -30
- package/src/models/host-to-path-props.ts +12 -12
- package/src/models/index.ts +16 -16
- package/src/models/json-object.ts +8 -8
- package/src/models/locals-props.ts +36 -36
- package/src/models/logger-props.ts +84 -84
- package/src/models/simple-storage-props.ts +13 -14
- package/src/models/to-client-delivery-props.ts +6 -6
- package/tsconfig.json +115 -115
- package/dev/plugin-gen-versions.js +0 -20
package/src/lib/db/db-mysql.ts
CHANGED
|
@@ -1,250 +1,249 @@
|
|
|
1
|
-
/*
|
|
2
|
-
npm install mysql2
|
|
3
|
-
npm install --save-dev @types/mysql2
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
import { createPool, Pool, PoolConnection, RowDataPacket, OkPacket, ResultSetHeader } from 'mysql2/promise';
|
|
7
|
-
import { Logger } from '../logger';
|
|
8
|
-
import { Db } from './db';
|
|
9
|
-
import { DbConfig } from '../../models/db-config';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
connection = mysql.createConnection({
|
|
13
|
-
host : 'localhost',
|
|
14
|
-
user : '***',
|
|
15
|
-
password : '***',
|
|
16
|
-
port : 3306,
|
|
17
|
-
database: '***',
|
|
18
|
-
insecureAuth: true,
|
|
19
|
-
//debug: true,
|
|
20
|
-
});
|
|
21
|
-
connection.connect();
|
|
22
|
-
|
|
23
|
-
connection.end();
|
|
24
|
-
|
|
25
|
-
getConn: function (config) {
|
|
26
|
-
config.host = config.host || "localhost";
|
|
27
|
-
config.port = config.port || 3306;
|
|
28
|
-
connection = mysql.createConnection({
|
|
29
|
-
host: config.host,
|
|
30
|
-
user: config.user,
|
|
31
|
-
password: config.password,
|
|
32
|
-
port: config.port,
|
|
33
|
-
database: config.database,
|
|
34
|
-
insecureAuth: config.insecureAuth,
|
|
35
|
-
debug: config.debug,
|
|
36
|
-
});
|
|
37
|
-
connection.connect();
|
|
38
|
-
|
|
39
|
-
this.debug = config.debug || false;
|
|
40
|
-
var thisObj = this;
|
|
41
|
-
connection.on("error", function (err) {
|
|
42
|
-
if (!err.fatal) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (err.code !== "PROTOCOL_CONNECTION_LOST") {
|
|
47
|
-
throw err;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//console.log('Re-connecting lost connection: ' + err.stack);
|
|
51
|
-
console.log("Re-connecting lost connection: " + err);
|
|
52
|
-
thisObj.connection = thisObj.getConn(config);
|
|
53
|
-
});
|
|
54
|
-
this.connection = connection;
|
|
55
|
-
return connection;
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
query: function (cb, sql) {
|
|
59
|
-
try {
|
|
60
|
-
var conn = this.connection;
|
|
61
|
-
sql = this.replacePrefix(sql);
|
|
62
|
-
console.log("query:" + sql);
|
|
63
|
-
conn.query(sql, cb);
|
|
64
|
-
} catch (err) {
|
|
65
|
-
console.log(err);
|
|
66
|
-
if (err.code == "PROTOCOL_CONNECTION_LOST") {
|
|
67
|
-
var conn = this.connection;
|
|
68
|
-
conn.query(sql, cb);
|
|
69
|
-
} else {
|
|
70
|
-
cb(err, false);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
escape: function (val) {
|
|
77
|
-
return mysql.escape(val);
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
escapeId: function (id) {
|
|
81
|
-
return mysql.escapeId(id);
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
private
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
npm install mysql2
|
|
3
|
+
npm install --save-dev @types/mysql2
|
|
4
|
+
|
|
5
|
+
*/
|
|
6
|
+
import { createPool, Pool, PoolConnection, RowDataPacket, OkPacket, ResultSetHeader } from 'mysql2/promise';
|
|
7
|
+
import { Logger } from '../logger';
|
|
8
|
+
import { Db } from './db';
|
|
9
|
+
import { DbConfig } from '../../models/db-config';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
connection = mysql.createConnection({
|
|
13
|
+
host : 'localhost',
|
|
14
|
+
user : '***',
|
|
15
|
+
password : '***',
|
|
16
|
+
port : 3306,
|
|
17
|
+
database: '***',
|
|
18
|
+
insecureAuth: true,
|
|
19
|
+
//debug: true,
|
|
20
|
+
});
|
|
21
|
+
connection.connect();
|
|
22
|
+
|
|
23
|
+
connection.end();
|
|
24
|
+
|
|
25
|
+
getConn: function (config) {
|
|
26
|
+
config.host = config.host || "localhost";
|
|
27
|
+
config.port = config.port || 3306;
|
|
28
|
+
connection = mysql.createConnection({
|
|
29
|
+
host: config.host,
|
|
30
|
+
user: config.user,
|
|
31
|
+
password: config.password,
|
|
32
|
+
port: config.port,
|
|
33
|
+
database: config.database,
|
|
34
|
+
insecureAuth: config.insecureAuth,
|
|
35
|
+
debug: config.debug,
|
|
36
|
+
});
|
|
37
|
+
connection.connect();
|
|
38
|
+
|
|
39
|
+
this.debug = config.debug || false;
|
|
40
|
+
var thisObj = this;
|
|
41
|
+
connection.on("error", function (err) {
|
|
42
|
+
if (!err.fatal) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (err.code !== "PROTOCOL_CONNECTION_LOST") {
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//console.log('Re-connecting lost connection: ' + err.stack);
|
|
51
|
+
console.log("Re-connecting lost connection: " + err);
|
|
52
|
+
thisObj.connection = thisObj.getConn(config);
|
|
53
|
+
});
|
|
54
|
+
this.connection = connection;
|
|
55
|
+
return connection;
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
query: function (cb, sql) {
|
|
59
|
+
try {
|
|
60
|
+
var conn = this.connection;
|
|
61
|
+
sql = this.replacePrefix(sql);
|
|
62
|
+
console.log("query:" + sql);
|
|
63
|
+
conn.query(sql, cb);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.log(err);
|
|
66
|
+
if (err.code == "PROTOCOL_CONNECTION_LOST") {
|
|
67
|
+
var conn = this.connection;
|
|
68
|
+
conn.query(sql, cb);
|
|
69
|
+
} else {
|
|
70
|
+
cb(err, false);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
escape: function (val) {
|
|
77
|
+
return mysql.escape(val);
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
escapeId: function (id) {
|
|
81
|
+
return mysql.escapeId(id);
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
const logger = new Logger('db-mysql');
|
|
87
|
+
|
|
88
|
+
export class DbMysql extends Db {
|
|
89
|
+
private pool!: Pool;
|
|
90
|
+
private connection!: PoolConnection;
|
|
91
|
+
|
|
92
|
+
constructor(option: DbConfig) {
|
|
93
|
+
super(option);
|
|
94
|
+
|
|
95
|
+
this.pool = createPool({
|
|
96
|
+
host: option.host || 'localhost',
|
|
97
|
+
user: option.user,
|
|
98
|
+
password: option.password,
|
|
99
|
+
database: option.database,
|
|
100
|
+
port: option.port || 3306,
|
|
101
|
+
/* Math.max(2, Math.floor(10 / numCPUs)); */
|
|
102
|
+
connectionLimit: 2,
|
|
103
|
+
waitForConnections: true,
|
|
104
|
+
queueLimit: 0,
|
|
105
|
+
namedPlaceholders: true,
|
|
106
|
+
supportBigNumbers: true,
|
|
107
|
+
bigNumberStrings: true,
|
|
108
|
+
// Enable for debugging
|
|
109
|
+
// debug: logger.isDebug()
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Test the connection
|
|
113
|
+
if (logger.isDebug()) {
|
|
114
|
+
this.testConnection();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async close() {
|
|
119
|
+
if (this.pool) {
|
|
120
|
+
await this.pool.end();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async connect() {
|
|
125
|
+
try {
|
|
126
|
+
this.connection = await this.pool.getConnection();
|
|
127
|
+
return Promise.resolve();
|
|
128
|
+
} catch (error: any) {
|
|
129
|
+
logger.error('Failed to connect to MySQL:', error);
|
|
130
|
+
return Promise.reject(error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public async nativeQuery(sql: string, params?: any, isSelect: boolean = true): Promise<any> {
|
|
135
|
+
let connection: PoolConnection | null = null;
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
connection = await this.pool.getConnection();
|
|
139
|
+
|
|
140
|
+
if (logger.isDebug()) {
|
|
141
|
+
logger.debug('Executing query:', { sql, params });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let result: any;
|
|
145
|
+
|
|
146
|
+
if (isSelect) {
|
|
147
|
+
const [rows] = await connection.execute<RowDataPacket[]>(sql, params);
|
|
148
|
+
result = rows;
|
|
149
|
+
} else {
|
|
150
|
+
const [resultSet] = await connection.execute<ResultSetHeader>(sql, params);
|
|
151
|
+
// For INSERT, UPDATE, DELETE operations, return the result set
|
|
152
|
+
result = [resultSet];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (logger.isDebug()) {
|
|
156
|
+
logger.debug('Query result:', { sql, rowCount: Array.isArray(result) ? result.length : 1 });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return result;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
logger.error('Error executing query:', { sql, params, error });
|
|
162
|
+
throw error;
|
|
163
|
+
} finally {
|
|
164
|
+
if (connection) {
|
|
165
|
+
connection.release();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public async truncateTable(tableName: string): Promise<any> {
|
|
171
|
+
// MySQL uses TRUNCATE TABLE which is more efficient than DELETE FROM
|
|
172
|
+
return this.execute(`TRUNCATE TABLE ${tableName}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public async getTableCount(tableName: string): Promise<number> {
|
|
176
|
+
const result = await this.select(`SELECT COUNT(*) as c FROM ${tableName}`);
|
|
177
|
+
return result[0].c;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public async getAllTables(addCount: boolean = false): Promise<any[]> {
|
|
181
|
+
const query = `
|
|
182
|
+
SELECT
|
|
183
|
+
TABLE_NAME as name,
|
|
184
|
+
TABLE_SCHEMA as schema_name,
|
|
185
|
+
TABLE_TYPE as type,
|
|
186
|
+
ENGINE as engine,
|
|
187
|
+
TABLE_ROWS as row_count,
|
|
188
|
+
DATA_LENGTH as data_length,
|
|
189
|
+
INDEX_LENGTH as index_length,
|
|
190
|
+
CREATE_TIME as create_time,
|
|
191
|
+
UPDATE_TIME as update_time
|
|
192
|
+
FROM
|
|
193
|
+
information_schema.TABLES
|
|
194
|
+
WHERE
|
|
195
|
+
TABLE_SCHEMA = DATABASE()
|
|
196
|
+
`;
|
|
197
|
+
|
|
198
|
+
const result = await this.select(query);
|
|
199
|
+
|
|
200
|
+
if (result && addCount) {
|
|
201
|
+
for (const table of result) {
|
|
202
|
+
try {
|
|
203
|
+
table.count = await this.getTableCount(table.name);
|
|
204
|
+
} catch (error: any) {
|
|
205
|
+
logger.error(`Error getting count for table ${table.name}:`, error);
|
|
206
|
+
table.count = -1; // Indicate error
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return result || [];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public async getTableInfo(table: string): Promise<any> {
|
|
215
|
+
const query = `
|
|
216
|
+
SELECT
|
|
217
|
+
COLUMN_NAME as name,
|
|
218
|
+
DATA_TYPE as type,
|
|
219
|
+
IS_NULLABLE as is_nullable,
|
|
220
|
+
COLUMN_DEFAULT as default_value,
|
|
221
|
+
COLUMN_KEY as key,
|
|
222
|
+
EXTRA as extra,
|
|
223
|
+
CHARACTER_MAXIMUM_LENGTH as max_length,
|
|
224
|
+
NUMERIC_PRECISION as numeric_precision,
|
|
225
|
+
NUMERIC_SCALE as numeric_scale,
|
|
226
|
+
COLUMN_COMMENT as comment
|
|
227
|
+
FROM
|
|
228
|
+
information_schema.COLUMNS
|
|
229
|
+
WHERE
|
|
230
|
+
TABLE_SCHEMA = DATABASE()
|
|
231
|
+
AND TABLE_NAME = ?
|
|
232
|
+
ORDER BY
|
|
233
|
+
ORDINAL_POSITION
|
|
234
|
+
`;
|
|
235
|
+
|
|
236
|
+
return await this.select(query, [table]);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
public async testConnection() {
|
|
240
|
+
try {
|
|
241
|
+
const [result] = await this.pool.query('SELECT 1 as test');
|
|
242
|
+
logger.debug('MySQL connection test successful:', result);
|
|
243
|
+
return true;
|
|
244
|
+
} catch (error: any) {
|
|
245
|
+
logger.error('MySQL connection test failed:', error);
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|