@berthojoris/mcp-mysql-server 1.4.6 → 1.4.12
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/CHANGELOG.md +132 -0
- package/README.md +439 -0
- package/dist/db/connection.d.ts +3 -0
- package/dist/db/connection.js +20 -0
- package/dist/db/queryLogger.d.ts +60 -0
- package/dist/db/queryLogger.js +189 -0
- package/dist/index.d.ts +19 -0
- package/dist/mcp-server.js +24 -1
- package/dist/tools/crudTools.d.ts +4 -0
- package/dist/tools/crudTools.js +18 -9
- package/dist/tools/dataExportTools.d.ts +2 -0
- package/dist/tools/dataExportTools.js +6 -3
- package/dist/tools/databaseTools.d.ts +3 -0
- package/dist/tools/databaseTools.js +14 -7
- package/dist/tools/ddlTools.d.ts +4 -0
- package/dist/tools/ddlTools.js +18 -8
- package/dist/tools/queryTools.d.ts +2 -0
- package/dist/tools/queryTools.js +4 -0
- package/dist/tools/storedProcedureTools.d.ts +2 -0
- package/dist/tools/storedProcedureTools.js +10 -5
- package/dist/tools/transactionTools.d.ts +1 -0
- package/dist/tools/transactionTools.js +4 -2
- package/dist/tools/utilityTools.d.ts +1 -0
- package/dist/tools/utilityTools.js +4 -2
- package/package.json +1 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export interface QueryLog {
|
|
2
|
+
sql: string;
|
|
3
|
+
params?: any[];
|
|
4
|
+
duration: number;
|
|
5
|
+
timestamp: string;
|
|
6
|
+
status: 'success' | 'error';
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class QueryLogger {
|
|
10
|
+
private static logs;
|
|
11
|
+
private static readonly MAX_LOGS;
|
|
12
|
+
private static readonly MAX_SQL_LENGTH;
|
|
13
|
+
private static readonly MAX_PARAM_LENGTH;
|
|
14
|
+
private static readonly MAX_PARAM_ITEMS;
|
|
15
|
+
/**
|
|
16
|
+
* Safely stringify a value with truncation and error handling
|
|
17
|
+
*/
|
|
18
|
+
private static safeStringify;
|
|
19
|
+
/**
|
|
20
|
+
* Truncate SQL string to prevent memory issues
|
|
21
|
+
*/
|
|
22
|
+
private static truncateSQL;
|
|
23
|
+
/**
|
|
24
|
+
* Create a memory-safe copy of parameters
|
|
25
|
+
*/
|
|
26
|
+
private static sanitizeParams;
|
|
27
|
+
/**
|
|
28
|
+
* Log a query execution
|
|
29
|
+
*/
|
|
30
|
+
static log(sql: string, params: any[] | undefined, duration: number, status: 'success' | 'error', error?: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get all logged queries (returns shallow copy of array)
|
|
33
|
+
*/
|
|
34
|
+
static getLogs(): QueryLog[];
|
|
35
|
+
/**
|
|
36
|
+
* Get the last N logged queries
|
|
37
|
+
*/
|
|
38
|
+
static getLastLogs(count?: number): QueryLog[];
|
|
39
|
+
/**
|
|
40
|
+
* Get logs for the current session (last query execution)
|
|
41
|
+
*/
|
|
42
|
+
static getLastLog(): QueryLog | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Clear all logs
|
|
45
|
+
*/
|
|
46
|
+
static clearLogs(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Format SQL for better readability
|
|
49
|
+
*/
|
|
50
|
+
private static formatSQL;
|
|
51
|
+
/**
|
|
52
|
+
* Get logs as formatted string for output with enhanced human readability
|
|
53
|
+
* Optimized for Kilocode and other MCP clients
|
|
54
|
+
*/
|
|
55
|
+
static formatLogs(logs: QueryLog[]): string;
|
|
56
|
+
/**
|
|
57
|
+
* Get logs as compact formatted string (for backward compatibility)
|
|
58
|
+
*/
|
|
59
|
+
static formatLogsCompact(logs: QueryLog[]): string;
|
|
60
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryLogger = void 0;
|
|
4
|
+
class QueryLogger {
|
|
5
|
+
/**
|
|
6
|
+
* Safely stringify a value with truncation and error handling
|
|
7
|
+
*/
|
|
8
|
+
static safeStringify(value, maxLength = 100) {
|
|
9
|
+
try {
|
|
10
|
+
if (value === null)
|
|
11
|
+
return 'null';
|
|
12
|
+
if (value === undefined)
|
|
13
|
+
return 'undefined';
|
|
14
|
+
if (typeof value === 'string') {
|
|
15
|
+
return value.length > maxLength ? value.substring(0, maxLength) + '...' : value;
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
18
|
+
return String(value);
|
|
19
|
+
}
|
|
20
|
+
if (typeof value === 'bigint') {
|
|
21
|
+
return value.toString() + 'n';
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
if (value.length === 0)
|
|
25
|
+
return '[]';
|
|
26
|
+
const items = value.slice(0, 3).map(v => this.safeStringify(v, 30));
|
|
27
|
+
return value.length > 3
|
|
28
|
+
? `[${items.join(', ')}, ... +${value.length - 3} more]`
|
|
29
|
+
: `[${items.join(', ')}]`;
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === 'object') {
|
|
32
|
+
const str = JSON.stringify(value);
|
|
33
|
+
return str.length > maxLength ? str.substring(0, maxLength) + '...}' : str;
|
|
34
|
+
}
|
|
35
|
+
return String(value);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return '[Unstringifiable]';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Truncate SQL string to prevent memory issues
|
|
43
|
+
*/
|
|
44
|
+
static truncateSQL(sql) {
|
|
45
|
+
if (sql.length <= this.MAX_SQL_LENGTH)
|
|
46
|
+
return sql;
|
|
47
|
+
return sql.substring(0, this.MAX_SQL_LENGTH) + `... [truncated ${sql.length - this.MAX_SQL_LENGTH} chars]`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create a memory-safe copy of parameters
|
|
51
|
+
*/
|
|
52
|
+
static sanitizeParams(params) {
|
|
53
|
+
if (!params || params.length === 0)
|
|
54
|
+
return undefined;
|
|
55
|
+
// Only keep first N params to prevent memory issues
|
|
56
|
+
const limitedParams = params.slice(0, this.MAX_PARAM_ITEMS);
|
|
57
|
+
// Create deep copy to prevent reference issues
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(JSON.stringify(limitedParams));
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// If JSON serialization fails, create safe string representations
|
|
63
|
+
return limitedParams.map(p => this.safeStringify(p, 50));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Log a query execution
|
|
68
|
+
*/
|
|
69
|
+
static log(sql, params, duration, status, error) {
|
|
70
|
+
const log = {
|
|
71
|
+
sql: this.truncateSQL(sql),
|
|
72
|
+
params: this.sanitizeParams(params),
|
|
73
|
+
duration,
|
|
74
|
+
timestamp: new Date().toISOString(),
|
|
75
|
+
status,
|
|
76
|
+
error: error ? (error.length > 200 ? error.substring(0, 200) + '...' : error) : undefined
|
|
77
|
+
};
|
|
78
|
+
this.logs.push(log);
|
|
79
|
+
// Keep only the last MAX_LOGS entries
|
|
80
|
+
if (this.logs.length > this.MAX_LOGS) {
|
|
81
|
+
this.logs.shift();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get all logged queries (returns shallow copy of array)
|
|
86
|
+
*/
|
|
87
|
+
static getLogs() {
|
|
88
|
+
return [...this.logs];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the last N logged queries
|
|
92
|
+
*/
|
|
93
|
+
static getLastLogs(count = 10) {
|
|
94
|
+
// Ensure count doesn't exceed array length to prevent issues
|
|
95
|
+
const safeCount = Math.min(Math.max(1, count), this.logs.length);
|
|
96
|
+
return this.logs.slice(-safeCount);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get logs for the current session (last query execution)
|
|
100
|
+
*/
|
|
101
|
+
static getLastLog() {
|
|
102
|
+
return this.logs[this.logs.length - 1];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Clear all logs
|
|
106
|
+
*/
|
|
107
|
+
static clearLogs() {
|
|
108
|
+
this.logs = [];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Format SQL for better readability
|
|
112
|
+
*/
|
|
113
|
+
static formatSQL(sql) {
|
|
114
|
+
// Add line breaks for better readability
|
|
115
|
+
return sql
|
|
116
|
+
.replace(/\s+/g, ' ') // Normalize whitespace
|
|
117
|
+
.replace(/\b(SELECT|FROM|WHERE|JOIN|LEFT JOIN|RIGHT JOIN|INNER JOIN|OUTER JOIN|GROUP BY|ORDER BY|HAVING|LIMIT|UNION|INSERT INTO|UPDATE|DELETE FROM|SET|VALUES|CREATE|ALTER|DROP|TRUNCATE|BEGIN|COMMIT|ROLLBACK|CALL)\b/gi, '\n$1')
|
|
118
|
+
.replace(/,\s*/g, ',\n ') // Add line breaks after commas
|
|
119
|
+
.trim();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get logs as formatted string for output with enhanced human readability
|
|
123
|
+
* Optimized for Kilocode and other MCP clients
|
|
124
|
+
*/
|
|
125
|
+
static formatLogs(logs) {
|
|
126
|
+
if (logs.length === 0)
|
|
127
|
+
return '';
|
|
128
|
+
return logs.map((log, index) => {
|
|
129
|
+
// Format the SQL for better readability
|
|
130
|
+
const formattedSQL = this.formatSQL(log.sql);
|
|
131
|
+
// Format parameters
|
|
132
|
+
let paramStr = '';
|
|
133
|
+
if (log.params && log.params.length > 0) {
|
|
134
|
+
try {
|
|
135
|
+
const paramsJson = JSON.stringify(log.params, null, 2);
|
|
136
|
+
paramStr = paramsJson.length > this.MAX_PARAM_LENGTH
|
|
137
|
+
? `\n📋 Parameters:\n${paramsJson.substring(0, this.MAX_PARAM_LENGTH)}...`
|
|
138
|
+
: `\n📋 Parameters:\n${paramsJson}`;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
paramStr = '\n📋 Parameters: [Error serializing]';
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Format error if present
|
|
145
|
+
const errorStr = log.error ? `\n❌ Error: ${log.error}` : '';
|
|
146
|
+
// Format status with emoji for better visibility
|
|
147
|
+
const statusEmoji = log.status === 'success' ? '✅' : '❌';
|
|
148
|
+
const statusText = log.status === 'success' ? 'SUCCESS' : 'ERROR';
|
|
149
|
+
// Build the formatted log entry with clear visual hierarchy
|
|
150
|
+
return `━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
151
|
+
${statusEmoji} SQL Query #${index + 1} - ${statusText}
|
|
152
|
+
⏱️ Execution Time: ${log.duration}ms
|
|
153
|
+
🕐 Timestamp: ${log.timestamp}
|
|
154
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
155
|
+
|
|
156
|
+
📝 SQL Query:
|
|
157
|
+
${formattedSQL}${paramStr}${errorStr}`;
|
|
158
|
+
}).join('\n\n');
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get logs as compact formatted string (for backward compatibility)
|
|
162
|
+
*/
|
|
163
|
+
static formatLogsCompact(logs) {
|
|
164
|
+
if (logs.length === 0)
|
|
165
|
+
return '';
|
|
166
|
+
return logs.map((log, index) => {
|
|
167
|
+
let paramStr = '';
|
|
168
|
+
if (log.params && log.params.length > 0) {
|
|
169
|
+
try {
|
|
170
|
+
const paramsJson = JSON.stringify(log.params);
|
|
171
|
+
paramStr = paramsJson.length > this.MAX_PARAM_LENGTH
|
|
172
|
+
? ` | Params: ${paramsJson.substring(0, this.MAX_PARAM_LENGTH)}...`
|
|
173
|
+
: ` | Params: ${paramsJson}`;
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
paramStr = ' | Params: [Error serializing]';
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const errorStr = log.error ? ` | Error: ${log.error}` : '';
|
|
180
|
+
return `[${index + 1}] ${log.timestamp} | ${log.sql}${paramStr} | Duration: ${log.duration}ms | Status: ${log.status}${errorStr}`;
|
|
181
|
+
}).join('\n');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.QueryLogger = QueryLogger;
|
|
185
|
+
QueryLogger.logs = [];
|
|
186
|
+
QueryLogger.MAX_LOGS = 100;
|
|
187
|
+
QueryLogger.MAX_SQL_LENGTH = 500; // Truncate SQL beyond this
|
|
188
|
+
QueryLogger.MAX_PARAM_LENGTH = 200; // Truncate params beyond this
|
|
189
|
+
QueryLogger.MAX_PARAM_ITEMS = 5; // Only log first N params
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare class MySQLMCP {
|
|
|
19
19
|
status: string;
|
|
20
20
|
data?: string[];
|
|
21
21
|
error?: string;
|
|
22
|
+
queryLog?: string;
|
|
22
23
|
}>;
|
|
23
24
|
listTables(params: {
|
|
24
25
|
database?: string;
|
|
@@ -26,6 +27,7 @@ export declare class MySQLMCP {
|
|
|
26
27
|
status: string;
|
|
27
28
|
data?: import("./validation/schemas").TableInfo[];
|
|
28
29
|
error?: string;
|
|
30
|
+
queryLog?: string;
|
|
29
31
|
}>;
|
|
30
32
|
readTableSchema(params: {
|
|
31
33
|
table_name: string;
|
|
@@ -33,6 +35,7 @@ export declare class MySQLMCP {
|
|
|
33
35
|
status: string;
|
|
34
36
|
data?: import("./validation/schemas").ColumnInfo[];
|
|
35
37
|
error?: string;
|
|
38
|
+
queryLog?: string;
|
|
36
39
|
}>;
|
|
37
40
|
createRecord(params: {
|
|
38
41
|
table_name: string;
|
|
@@ -41,6 +44,7 @@ export declare class MySQLMCP {
|
|
|
41
44
|
status: string;
|
|
42
45
|
data?: any;
|
|
43
46
|
error?: string;
|
|
47
|
+
queryLog?: string;
|
|
44
48
|
}>;
|
|
45
49
|
readRecords(params: {
|
|
46
50
|
table_name: string;
|
|
@@ -58,6 +62,7 @@ export declare class MySQLMCP {
|
|
|
58
62
|
data?: any[];
|
|
59
63
|
total?: number;
|
|
60
64
|
error?: string;
|
|
65
|
+
queryLog?: string;
|
|
61
66
|
}>;
|
|
62
67
|
updateRecord(params: {
|
|
63
68
|
table_name: string;
|
|
@@ -69,6 +74,7 @@ export declare class MySQLMCP {
|
|
|
69
74
|
affectedRows: number;
|
|
70
75
|
};
|
|
71
76
|
error?: string;
|
|
77
|
+
queryLog?: string;
|
|
72
78
|
}>;
|
|
73
79
|
deleteRecord(params: {
|
|
74
80
|
table_name: string;
|
|
@@ -79,6 +85,7 @@ export declare class MySQLMCP {
|
|
|
79
85
|
affectedRows: number;
|
|
80
86
|
};
|
|
81
87
|
error?: string;
|
|
88
|
+
queryLog?: string;
|
|
82
89
|
}>;
|
|
83
90
|
runQuery(params: {
|
|
84
91
|
query: string;
|
|
@@ -87,6 +94,7 @@ export declare class MySQLMCP {
|
|
|
87
94
|
status: string;
|
|
88
95
|
data?: any[];
|
|
89
96
|
error?: string;
|
|
97
|
+
queryLog?: string;
|
|
90
98
|
}>;
|
|
91
99
|
executeSql(params: {
|
|
92
100
|
query: string;
|
|
@@ -95,21 +103,25 @@ export declare class MySQLMCP {
|
|
|
95
103
|
status: string;
|
|
96
104
|
data?: any;
|
|
97
105
|
error?: string;
|
|
106
|
+
queryLog?: string;
|
|
98
107
|
}>;
|
|
99
108
|
createTable(params: any): Promise<{
|
|
100
109
|
status: string;
|
|
101
110
|
data?: any;
|
|
102
111
|
error?: string;
|
|
112
|
+
queryLog?: string;
|
|
103
113
|
}>;
|
|
104
114
|
alterTable(params: any): Promise<{
|
|
105
115
|
status: string;
|
|
106
116
|
data?: any;
|
|
107
117
|
error?: string;
|
|
118
|
+
queryLog?: string;
|
|
108
119
|
}>;
|
|
109
120
|
dropTable(params: any): Promise<{
|
|
110
121
|
status: string;
|
|
111
122
|
data?: any;
|
|
112
123
|
error?: string;
|
|
124
|
+
queryLog?: string;
|
|
113
125
|
}>;
|
|
114
126
|
executeDdl(params: {
|
|
115
127
|
query: string;
|
|
@@ -117,6 +129,7 @@ export declare class MySQLMCP {
|
|
|
117
129
|
status: string;
|
|
118
130
|
data?: any;
|
|
119
131
|
error?: string;
|
|
132
|
+
queryLog?: string;
|
|
120
133
|
}>;
|
|
121
134
|
describeConnection(): Promise<{
|
|
122
135
|
status: string;
|
|
@@ -134,6 +147,7 @@ export declare class MySQLMCP {
|
|
|
134
147
|
status: string;
|
|
135
148
|
data?: any;
|
|
136
149
|
error?: string;
|
|
150
|
+
queryLog?: string;
|
|
137
151
|
}>;
|
|
138
152
|
beginTransaction(params?: {
|
|
139
153
|
transactionId?: string;
|
|
@@ -165,6 +179,7 @@ export declare class MySQLMCP {
|
|
|
165
179
|
status: "success" | "error";
|
|
166
180
|
data?: any;
|
|
167
181
|
error?: string;
|
|
182
|
+
queryLog?: string;
|
|
168
183
|
} | {
|
|
169
184
|
status: string;
|
|
170
185
|
error: string | undefined;
|
|
@@ -175,6 +190,7 @@ export declare class MySQLMCP {
|
|
|
175
190
|
status: string;
|
|
176
191
|
data?: any[];
|
|
177
192
|
error?: string;
|
|
193
|
+
queryLog?: string;
|
|
178
194
|
}>;
|
|
179
195
|
getStoredProcedureInfo(params: {
|
|
180
196
|
procedure_name: string;
|
|
@@ -183,6 +199,7 @@ export declare class MySQLMCP {
|
|
|
183
199
|
status: string;
|
|
184
200
|
data?: any;
|
|
185
201
|
error?: string;
|
|
202
|
+
queryLog?: string;
|
|
186
203
|
}>;
|
|
187
204
|
executeStoredProcedure(params: {
|
|
188
205
|
procedure_name: string;
|
|
@@ -241,6 +258,7 @@ export declare class MySQLMCP {
|
|
|
241
258
|
status: string;
|
|
242
259
|
data?: any;
|
|
243
260
|
error?: string;
|
|
261
|
+
queryLog?: string;
|
|
244
262
|
}>;
|
|
245
263
|
exportQueryToCSV(params: {
|
|
246
264
|
query: string;
|
|
@@ -250,6 +268,7 @@ export declare class MySQLMCP {
|
|
|
250
268
|
status: string;
|
|
251
269
|
data?: any;
|
|
252
270
|
error?: string;
|
|
271
|
+
queryLog?: string;
|
|
253
272
|
}>;
|
|
254
273
|
getFeatureStatus(): {
|
|
255
274
|
status: string;
|
package/dist/mcp-server.js
CHANGED
|
@@ -932,11 +932,16 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
932
932
|
}
|
|
933
933
|
// Handle the result based on status
|
|
934
934
|
if (result.status === "error") {
|
|
935
|
+
// Include query log in error response if available
|
|
936
|
+
let errorText = `Error: ${result.error}`;
|
|
937
|
+
if ('queryLog' in result && result.queryLog) {
|
|
938
|
+
errorText += `\n\n${result.queryLog}`;
|
|
939
|
+
}
|
|
935
940
|
return {
|
|
936
941
|
content: [
|
|
937
942
|
{
|
|
938
943
|
type: "text",
|
|
939
|
-
text:
|
|
944
|
+
text: errorText,
|
|
940
945
|
},
|
|
941
946
|
],
|
|
942
947
|
isError: true,
|
|
@@ -968,6 +973,24 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
968
973
|
// Fallback
|
|
969
974
|
responseData = result;
|
|
970
975
|
}
|
|
976
|
+
// NEW APPROACH: Wrap the data with SQL query as part of the response structure
|
|
977
|
+
// This forces the LLM to see and describe the SQL query as part of the data
|
|
978
|
+
if ('queryLog' in result && result.queryLog) {
|
|
979
|
+
const wrappedResponse = {
|
|
980
|
+
"⚠️ IMPORTANT_INSTRUCTION_TO_ASSISTANT": "ALWAYS display the SQL query execution details below to the user in your response. This is critical information that users need to see.",
|
|
981
|
+
"⚠️ SQL_QUERY_EXECUTED": result.queryLog,
|
|
982
|
+
"📊 RESULTS": responseData
|
|
983
|
+
};
|
|
984
|
+
return {
|
|
985
|
+
content: [
|
|
986
|
+
{
|
|
987
|
+
type: "text",
|
|
988
|
+
text: JSON.stringify(wrappedResponse, null, 2),
|
|
989
|
+
},
|
|
990
|
+
],
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
// If no query log, return data as before
|
|
971
994
|
return {
|
|
972
995
|
content: [
|
|
973
996
|
{
|
|
@@ -14,6 +14,7 @@ export declare class CrudTools {
|
|
|
14
14
|
status: string;
|
|
15
15
|
data?: any;
|
|
16
16
|
error?: string;
|
|
17
|
+
queryLog?: string;
|
|
17
18
|
}>;
|
|
18
19
|
/**
|
|
19
20
|
* Read records from the specified table with optional filters, pagination, and sorting
|
|
@@ -28,6 +29,7 @@ export declare class CrudTools {
|
|
|
28
29
|
data?: any[];
|
|
29
30
|
total?: number;
|
|
30
31
|
error?: string;
|
|
32
|
+
queryLog?: string;
|
|
31
33
|
}>;
|
|
32
34
|
/**
|
|
33
35
|
* Update records in the specified table based on conditions
|
|
@@ -42,6 +44,7 @@ export declare class CrudTools {
|
|
|
42
44
|
affectedRows: number;
|
|
43
45
|
};
|
|
44
46
|
error?: string;
|
|
47
|
+
queryLog?: string;
|
|
45
48
|
}>;
|
|
46
49
|
/**
|
|
47
50
|
* Delete records from the specified table based on conditions
|
|
@@ -55,6 +58,7 @@ export declare class CrudTools {
|
|
|
55
58
|
affectedRows: number;
|
|
56
59
|
};
|
|
57
60
|
error?: string;
|
|
61
|
+
queryLog?: string;
|
|
58
62
|
}>;
|
|
59
63
|
/**
|
|
60
64
|
* Bulk insert multiple records into the specified table
|
package/dist/tools/crudTools.js
CHANGED
|
@@ -64,13 +64,15 @@ class CrudTools {
|
|
|
64
64
|
data: {
|
|
65
65
|
insertId: result.insertId,
|
|
66
66
|
affectedRows: result.affectedRows
|
|
67
|
-
}
|
|
67
|
+
},
|
|
68
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
68
69
|
};
|
|
69
70
|
}
|
|
70
71
|
catch (error) {
|
|
71
72
|
return {
|
|
72
73
|
status: 'error',
|
|
73
|
-
error: error.message
|
|
74
|
+
error: error.message,
|
|
75
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
74
76
|
};
|
|
75
77
|
}
|
|
76
78
|
}
|
|
@@ -188,7 +190,8 @@ class CrudTools {
|
|
|
188
190
|
return {
|
|
189
191
|
status: 'success',
|
|
190
192
|
data: results,
|
|
191
|
-
total
|
|
193
|
+
total,
|
|
194
|
+
queryLog: this.db.getFormattedQueryLogs(2)
|
|
192
195
|
};
|
|
193
196
|
}
|
|
194
197
|
else {
|
|
@@ -198,14 +201,16 @@ class CrudTools {
|
|
|
198
201
|
return {
|
|
199
202
|
status: 'success',
|
|
200
203
|
data: results,
|
|
201
|
-
total: results.length
|
|
204
|
+
total: results.length,
|
|
205
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
202
206
|
};
|
|
203
207
|
}
|
|
204
208
|
}
|
|
205
209
|
catch (error) {
|
|
206
210
|
return {
|
|
207
211
|
status: 'error',
|
|
208
|
-
error: error.message
|
|
212
|
+
error: error.message,
|
|
213
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
209
214
|
};
|
|
210
215
|
}
|
|
211
216
|
}
|
|
@@ -320,13 +325,15 @@ class CrudTools {
|
|
|
320
325
|
status: 'success',
|
|
321
326
|
data: {
|
|
322
327
|
affectedRows: result.affectedRows
|
|
323
|
-
}
|
|
328
|
+
},
|
|
329
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
324
330
|
};
|
|
325
331
|
}
|
|
326
332
|
catch (error) {
|
|
327
333
|
return {
|
|
328
334
|
status: 'error',
|
|
329
|
-
error: error.message
|
|
335
|
+
error: error.message,
|
|
336
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
330
337
|
};
|
|
331
338
|
}
|
|
332
339
|
}
|
|
@@ -429,13 +436,15 @@ class CrudTools {
|
|
|
429
436
|
status: 'success',
|
|
430
437
|
data: {
|
|
431
438
|
affectedRows: result.affectedRows
|
|
432
|
-
}
|
|
439
|
+
},
|
|
440
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
433
441
|
};
|
|
434
442
|
}
|
|
435
443
|
catch (error) {
|
|
436
444
|
return {
|
|
437
445
|
status: 'error',
|
|
438
|
-
error: error.message
|
|
446
|
+
error: error.message,
|
|
447
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
439
448
|
};
|
|
440
449
|
}
|
|
441
450
|
}
|
|
@@ -17,6 +17,7 @@ export declare class DataExportTools {
|
|
|
17
17
|
status: string;
|
|
18
18
|
data?: any;
|
|
19
19
|
error?: string;
|
|
20
|
+
queryLog?: string;
|
|
20
21
|
}>;
|
|
21
22
|
/**
|
|
22
23
|
* Export query results to CSV format
|
|
@@ -29,5 +30,6 @@ export declare class DataExportTools {
|
|
|
29
30
|
status: string;
|
|
30
31
|
data?: any;
|
|
31
32
|
error?: string;
|
|
33
|
+
queryLog?: string;
|
|
32
34
|
}>;
|
|
33
35
|
}
|
|
@@ -195,7 +195,8 @@ class DataExportTools {
|
|
|
195
195
|
data: {
|
|
196
196
|
csv: include_headers ? '' : '',
|
|
197
197
|
row_count: 0
|
|
198
|
-
}
|
|
198
|
+
},
|
|
199
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
199
200
|
};
|
|
200
201
|
}
|
|
201
202
|
// Generate CSV
|
|
@@ -226,13 +227,15 @@ class DataExportTools {
|
|
|
226
227
|
data: {
|
|
227
228
|
csv: csv,
|
|
228
229
|
row_count: results.length
|
|
229
|
-
}
|
|
230
|
+
},
|
|
231
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
230
232
|
};
|
|
231
233
|
}
|
|
232
234
|
catch (error) {
|
|
233
235
|
return {
|
|
234
236
|
status: 'error',
|
|
235
|
-
error: error.message
|
|
237
|
+
error: error.message,
|
|
238
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
236
239
|
};
|
|
237
240
|
}
|
|
238
241
|
}
|
|
@@ -10,6 +10,7 @@ export declare class DatabaseTools {
|
|
|
10
10
|
status: string;
|
|
11
11
|
data?: string[];
|
|
12
12
|
error?: string;
|
|
13
|
+
queryLog?: string;
|
|
13
14
|
}>;
|
|
14
15
|
/**
|
|
15
16
|
* List all tables in the selected database
|
|
@@ -20,6 +21,7 @@ export declare class DatabaseTools {
|
|
|
20
21
|
status: string;
|
|
21
22
|
data?: TableInfo[];
|
|
22
23
|
error?: string;
|
|
24
|
+
queryLog?: string;
|
|
23
25
|
}>;
|
|
24
26
|
/**
|
|
25
27
|
* Read table schema (columns, types, keys, etc.)
|
|
@@ -30,5 +32,6 @@ export declare class DatabaseTools {
|
|
|
30
32
|
status: string;
|
|
31
33
|
data?: ColumnInfo[];
|
|
32
34
|
error?: string;
|
|
35
|
+
queryLog?: string;
|
|
33
36
|
}>;
|
|
34
37
|
}
|
|
@@ -31,18 +31,21 @@ class DatabaseTools {
|
|
|
31
31
|
if (!currentDatabase) {
|
|
32
32
|
return {
|
|
33
33
|
status: 'error',
|
|
34
|
-
error: 'No database selected. Please ensure your connection string includes a valid database name.'
|
|
34
|
+
error: 'No database selected. Please ensure your connection string includes a valid database name.',
|
|
35
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
return {
|
|
38
39
|
status: 'success',
|
|
39
|
-
data: [currentDatabase]
|
|
40
|
+
data: [currentDatabase],
|
|
41
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
catch (error) {
|
|
43
45
|
return {
|
|
44
46
|
status: 'error',
|
|
45
|
-
error: error.message
|
|
47
|
+
error: error.message,
|
|
48
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
46
49
|
};
|
|
47
50
|
}
|
|
48
51
|
}
|
|
@@ -86,13 +89,15 @@ class DatabaseTools {
|
|
|
86
89
|
});
|
|
87
90
|
return {
|
|
88
91
|
status: 'success',
|
|
89
|
-
data: tables
|
|
92
|
+
data: tables,
|
|
93
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
90
94
|
};
|
|
91
95
|
}
|
|
92
96
|
catch (error) {
|
|
93
97
|
return {
|
|
94
98
|
status: 'error',
|
|
95
|
-
error: error.message
|
|
99
|
+
error: error.message,
|
|
100
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
96
101
|
};
|
|
97
102
|
}
|
|
98
103
|
}
|
|
@@ -126,13 +131,15 @@ class DatabaseTools {
|
|
|
126
131
|
const results = await this.db.query(query, [params.table_name]);
|
|
127
132
|
return {
|
|
128
133
|
status: 'success',
|
|
129
|
-
data: results
|
|
134
|
+
data: results,
|
|
135
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
130
136
|
};
|
|
131
137
|
}
|
|
132
138
|
catch (error) {
|
|
133
139
|
return {
|
|
134
140
|
status: 'error',
|
|
135
|
-
error: error.message
|
|
141
|
+
error: error.message,
|
|
142
|
+
queryLog: this.db.getFormattedQueryLogs(1)
|
|
136
143
|
};
|
|
137
144
|
}
|
|
138
145
|
}
|