@berthojoris/mcp-mysql-server 1.10.2 → 1.10.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/CHANGELOG.md +25 -7
- package/DOCUMENTATIONS.md +2 -2
- package/README.md +1 -1
- package/dist/index.d.ts +0 -99
- package/dist/mcp-server.js +0 -21
- package/dist/tools/backupRestoreTools.d.ts +1 -6
- package/dist/tools/backupRestoreTools.js +99 -97
- package/dist/tools/constraintTools.d.ts +4 -11
- package/dist/tools/constraintTools.js +114 -115
- package/dist/tools/crudTools.d.ts +2 -6
- package/dist/tools/crudTools.js +186 -189
- package/dist/tools/dataExportTools.d.ts +0 -7
- package/dist/tools/dataExportTools.js +0 -15
- package/dist/tools/databaseTools.d.ts +1 -4
- package/dist/tools/databaseTools.js +29 -33
- package/dist/tools/ddlTools.d.ts +1 -5
- package/dist/tools/ddlTools.js +68 -53
- package/dist/tools/functionTools.d.ts +3 -9
- package/dist/tools/functionTools.js +111 -104
- package/dist/tools/indexTools.d.ts +3 -8
- package/dist/tools/indexTools.js +99 -95
- package/dist/tools/maintenanceTools.d.ts +2 -10
- package/dist/tools/maintenanceTools.js +66 -80
- package/dist/tools/migrationTools.d.ts +0 -5
- package/dist/tools/migrationTools.js +56 -24
- package/dist/tools/performanceTools.d.ts +1 -11
- package/dist/tools/performanceTools.js +278 -267
- package/dist/tools/processTools.d.ts +4 -13
- package/dist/tools/processTools.js +78 -80
- package/dist/tools/queryTools.d.ts +0 -2
- package/dist/tools/queryTools.js +0 -4
- package/dist/tools/schemaVersioningTools.d.ts +0 -9
- package/dist/tools/schemaVersioningTools.js +167 -166
- package/dist/tools/storedProcedureTools.d.ts +2 -4
- package/dist/tools/storedProcedureTools.js +143 -134
- package/dist/tools/transactionTools.d.ts +2 -3
- package/dist/tools/transactionTools.js +28 -29
- package/dist/tools/triggerTools.d.ts +3 -8
- package/dist/tools/triggerTools.js +98 -85
- package/dist/tools/utilityTools.d.ts +0 -1
- package/dist/tools/utilityTools.js +0 -2
- package/dist/tools/viewTools.d.ts +7 -13
- package/dist/tools/viewTools.js +100 -93
- package/package.json +1 -1
|
@@ -14,18 +14,19 @@ class TransactionTools {
|
|
|
14
14
|
*/
|
|
15
15
|
async beginTransaction(params) {
|
|
16
16
|
try {
|
|
17
|
-
const transactionId = params?.transactionId ||
|
|
17
|
+
const transactionId = params?.transactionId ||
|
|
18
|
+
`tx_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
18
19
|
await this.db.beginTransaction(transactionId);
|
|
19
20
|
return {
|
|
20
|
-
status:
|
|
21
|
+
status: "success",
|
|
21
22
|
transactionId,
|
|
22
|
-
message: `Transaction ${transactionId} started successfully
|
|
23
|
+
message: `Transaction ${transactionId} started successfully`,
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
catch (error) {
|
|
26
27
|
return {
|
|
27
|
-
status:
|
|
28
|
-
error: error.message
|
|
28
|
+
status: "error",
|
|
29
|
+
error: error.message,
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -36,20 +37,20 @@ class TransactionTools {
|
|
|
36
37
|
try {
|
|
37
38
|
if (!params.transactionId) {
|
|
38
39
|
return {
|
|
39
|
-
status:
|
|
40
|
-
error:
|
|
40
|
+
status: "error",
|
|
41
|
+
error: "Transaction ID is required",
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
await this.db.commitTransaction(params.transactionId);
|
|
44
45
|
return {
|
|
45
|
-
status:
|
|
46
|
-
message: `Transaction ${params.transactionId} committed successfully
|
|
46
|
+
status: "success",
|
|
47
|
+
message: `Transaction ${params.transactionId} committed successfully`,
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
catch (error) {
|
|
50
51
|
return {
|
|
51
|
-
status:
|
|
52
|
-
error: error.message
|
|
52
|
+
status: "error",
|
|
53
|
+
error: error.message,
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -60,20 +61,20 @@ class TransactionTools {
|
|
|
60
61
|
try {
|
|
61
62
|
if (!params.transactionId) {
|
|
62
63
|
return {
|
|
63
|
-
status:
|
|
64
|
-
error:
|
|
64
|
+
status: "error",
|
|
65
|
+
error: "Transaction ID is required",
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
await this.db.rollbackTransaction(params.transactionId);
|
|
68
69
|
return {
|
|
69
|
-
status:
|
|
70
|
-
message: `Transaction ${params.transactionId} rolled back successfully
|
|
70
|
+
status: "success",
|
|
71
|
+
message: `Transaction ${params.transactionId} rolled back successfully`,
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
74
|
catch (error) {
|
|
74
75
|
return {
|
|
75
|
-
status:
|
|
76
|
-
error: error.message
|
|
76
|
+
status: "error",
|
|
77
|
+
error: error.message,
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
80
|
}
|
|
@@ -84,15 +85,15 @@ class TransactionTools {
|
|
|
84
85
|
try {
|
|
85
86
|
const activeTransactions = this.db.getActiveTransactionIds();
|
|
86
87
|
return {
|
|
87
|
-
status:
|
|
88
|
+
status: "success",
|
|
88
89
|
activeTransactions,
|
|
89
|
-
message: `Found ${activeTransactions.length} active transaction(s)
|
|
90
|
+
message: `Found ${activeTransactions.length} active transaction(s)`,
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
93
|
catch (error) {
|
|
93
94
|
return {
|
|
94
|
-
status:
|
|
95
|
-
error: error.message
|
|
95
|
+
status: "error",
|
|
96
|
+
error: error.message,
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
}
|
|
@@ -103,28 +104,26 @@ class TransactionTools {
|
|
|
103
104
|
try {
|
|
104
105
|
if (!params.transactionId) {
|
|
105
106
|
return {
|
|
106
|
-
status:
|
|
107
|
-
error:
|
|
107
|
+
status: "error",
|
|
108
|
+
error: "Transaction ID is required",
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
if (!params.query) {
|
|
111
112
|
return {
|
|
112
|
-
status:
|
|
113
|
-
error:
|
|
113
|
+
status: "error",
|
|
114
|
+
error: "Query is required",
|
|
114
115
|
};
|
|
115
116
|
}
|
|
116
117
|
const result = await this.db.executeInTransaction(params.transactionId, params.query, params.params);
|
|
117
118
|
return {
|
|
118
|
-
status:
|
|
119
|
+
status: "success",
|
|
119
120
|
data: result,
|
|
120
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
123
|
catch (error) {
|
|
124
124
|
return {
|
|
125
|
-
status:
|
|
125
|
+
status: "error",
|
|
126
126
|
error: error.message,
|
|
127
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
128
127
|
};
|
|
129
128
|
}
|
|
130
129
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SecurityLayer } from
|
|
1
|
+
import { SecurityLayer } from "../security/securityLayer";
|
|
2
2
|
export declare class TriggerTools {
|
|
3
3
|
private db;
|
|
4
4
|
private security;
|
|
@@ -17,7 +17,6 @@ export declare class TriggerTools {
|
|
|
17
17
|
status: string;
|
|
18
18
|
data?: any[];
|
|
19
19
|
error?: string;
|
|
20
|
-
queryLog?: string;
|
|
21
20
|
}>;
|
|
22
21
|
/**
|
|
23
22
|
* Get detailed information about a specific trigger
|
|
@@ -29,7 +28,6 @@ export declare class TriggerTools {
|
|
|
29
28
|
status: string;
|
|
30
29
|
data?: any;
|
|
31
30
|
error?: string;
|
|
32
|
-
queryLog?: string;
|
|
33
31
|
}>;
|
|
34
32
|
/**
|
|
35
33
|
* Create a new trigger
|
|
@@ -37,8 +35,8 @@ export declare class TriggerTools {
|
|
|
37
35
|
createTrigger(params: {
|
|
38
36
|
trigger_name: string;
|
|
39
37
|
table_name: string;
|
|
40
|
-
timing:
|
|
41
|
-
event:
|
|
38
|
+
timing: "BEFORE" | "AFTER";
|
|
39
|
+
event: "INSERT" | "UPDATE" | "DELETE";
|
|
42
40
|
body: string;
|
|
43
41
|
definer?: string;
|
|
44
42
|
database?: string;
|
|
@@ -46,7 +44,6 @@ export declare class TriggerTools {
|
|
|
46
44
|
status: string;
|
|
47
45
|
data?: any;
|
|
48
46
|
error?: string;
|
|
49
|
-
queryLog?: string;
|
|
50
47
|
}>;
|
|
51
48
|
/**
|
|
52
49
|
* Drop a trigger
|
|
@@ -59,7 +56,6 @@ export declare class TriggerTools {
|
|
|
59
56
|
status: string;
|
|
60
57
|
message?: string;
|
|
61
58
|
error?: string;
|
|
62
|
-
queryLog?: string;
|
|
63
59
|
}>;
|
|
64
60
|
/**
|
|
65
61
|
* Show the CREATE statement for a trigger
|
|
@@ -71,6 +67,5 @@ export declare class TriggerTools {
|
|
|
71
67
|
status: string;
|
|
72
68
|
data?: any;
|
|
73
69
|
error?: string;
|
|
74
|
-
queryLog?: string;
|
|
75
70
|
}>;
|
|
76
71
|
}
|
|
@@ -19,26 +19,26 @@ class TriggerTools {
|
|
|
19
19
|
if (!connectedDatabase) {
|
|
20
20
|
return {
|
|
21
21
|
valid: false,
|
|
22
|
-
database:
|
|
23
|
-
error:
|
|
22
|
+
database: "",
|
|
23
|
+
error: "No database specified in connection string. Cannot access any database.",
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
if (!requestedDatabase) {
|
|
27
27
|
return {
|
|
28
28
|
valid: true,
|
|
29
|
-
database: connectedDatabase
|
|
29
|
+
database: connectedDatabase,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
if (requestedDatabase !== connectedDatabase) {
|
|
33
33
|
return {
|
|
34
34
|
valid: false,
|
|
35
|
-
database:
|
|
36
|
-
error: `Access denied. You can only access the connected database '${connectedDatabase}'. Requested database '${requestedDatabase}' is not allowed
|
|
35
|
+
database: "",
|
|
36
|
+
error: `Access denied. You can only access the connected database '${connectedDatabase}'. Requested database '${requestedDatabase}' is not allowed.`,
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
return {
|
|
40
40
|
valid: true,
|
|
41
|
-
database: connectedDatabase
|
|
41
|
+
database: connectedDatabase,
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
@@ -48,27 +48,30 @@ class TriggerTools {
|
|
|
48
48
|
try {
|
|
49
49
|
const dbValidation = this.validateDatabaseAccess(params?.database);
|
|
50
50
|
if (!dbValidation.valid) {
|
|
51
|
-
return { status:
|
|
51
|
+
return { status: "error", error: dbValidation.error };
|
|
52
52
|
}
|
|
53
53
|
const database = dbValidation.database;
|
|
54
|
-
let query = `
|
|
55
|
-
SELECT
|
|
56
|
-
TRIGGER_NAME as trigger_name,
|
|
57
|
-
EVENT_MANIPULATION as event,
|
|
58
|
-
EVENT_OBJECT_TABLE as table_name,
|
|
59
|
-
ACTION_TIMING as timing,
|
|
60
|
-
ACTION_STATEMENT as statement,
|
|
61
|
-
ACTION_ORIENTATION as orientation,
|
|
62
|
-
DEFINER as definer,
|
|
63
|
-
CREATED as created
|
|
64
|
-
FROM INFORMATION_SCHEMA.TRIGGERS
|
|
65
|
-
WHERE TRIGGER_SCHEMA = ?
|
|
54
|
+
let query = `
|
|
55
|
+
SELECT
|
|
56
|
+
TRIGGER_NAME as trigger_name,
|
|
57
|
+
EVENT_MANIPULATION as event,
|
|
58
|
+
EVENT_OBJECT_TABLE as table_name,
|
|
59
|
+
ACTION_TIMING as timing,
|
|
60
|
+
ACTION_STATEMENT as statement,
|
|
61
|
+
ACTION_ORIENTATION as orientation,
|
|
62
|
+
DEFINER as definer,
|
|
63
|
+
CREATED as created
|
|
64
|
+
FROM INFORMATION_SCHEMA.TRIGGERS
|
|
65
|
+
WHERE TRIGGER_SCHEMA = ?
|
|
66
66
|
`;
|
|
67
67
|
const queryParams = [database];
|
|
68
68
|
if (params?.table_name) {
|
|
69
69
|
const identifierValidation = this.security.validateIdentifier(params.table_name);
|
|
70
70
|
if (!identifierValidation.valid) {
|
|
71
|
-
return {
|
|
71
|
+
return {
|
|
72
|
+
status: "error",
|
|
73
|
+
error: identifierValidation.error || "Invalid table name",
|
|
74
|
+
};
|
|
72
75
|
}
|
|
73
76
|
query += ` AND EVENT_OBJECT_TABLE = ?`;
|
|
74
77
|
queryParams.push(params.table_name);
|
|
@@ -76,16 +79,14 @@ class TriggerTools {
|
|
|
76
79
|
query += ` ORDER BY EVENT_OBJECT_TABLE, ACTION_TIMING, EVENT_MANIPULATION`;
|
|
77
80
|
const results = await this.db.query(query, queryParams);
|
|
78
81
|
return {
|
|
79
|
-
status:
|
|
82
|
+
status: "success",
|
|
80
83
|
data: results,
|
|
81
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
82
84
|
};
|
|
83
85
|
}
|
|
84
86
|
catch (error) {
|
|
85
87
|
return {
|
|
86
|
-
status:
|
|
88
|
+
status: "error",
|
|
87
89
|
error: error.message,
|
|
88
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
89
90
|
};
|
|
90
91
|
}
|
|
91
92
|
}
|
|
@@ -96,58 +97,61 @@ class TriggerTools {
|
|
|
96
97
|
try {
|
|
97
98
|
const dbValidation = this.validateDatabaseAccess(params?.database);
|
|
98
99
|
if (!dbValidation.valid) {
|
|
99
|
-
return { status:
|
|
100
|
+
return { status: "error", error: dbValidation.error };
|
|
100
101
|
}
|
|
101
102
|
const { trigger_name } = params;
|
|
102
103
|
const database = dbValidation.database;
|
|
103
104
|
// Validate trigger name
|
|
104
105
|
const identifierValidation = this.security.validateIdentifier(trigger_name);
|
|
105
106
|
if (!identifierValidation.valid) {
|
|
106
|
-
return {
|
|
107
|
+
return {
|
|
108
|
+
status: "error",
|
|
109
|
+
error: identifierValidation.error || "Invalid trigger name",
|
|
110
|
+
};
|
|
107
111
|
}
|
|
108
|
-
const query = `
|
|
109
|
-
SELECT
|
|
110
|
-
TRIGGER_NAME as trigger_name,
|
|
111
|
-
EVENT_MANIPULATION as event,
|
|
112
|
-
EVENT_OBJECT_SCHEMA as schema_name,
|
|
113
|
-
EVENT_OBJECT_TABLE as table_name,
|
|
114
|
-
ACTION_ORDER as action_order,
|
|
115
|
-
ACTION_CONDITION as condition_value,
|
|
116
|
-
ACTION_STATEMENT as statement,
|
|
117
|
-
ACTION_ORIENTATION as orientation,
|
|
118
|
-
ACTION_TIMING as timing,
|
|
119
|
-
ACTION_REFERENCE_OLD_TABLE as old_table,
|
|
120
|
-
ACTION_REFERENCE_NEW_TABLE as new_table,
|
|
121
|
-
ACTION_REFERENCE_OLD_ROW as old_row,
|
|
122
|
-
ACTION_REFERENCE_NEW_ROW as new_row,
|
|
123
|
-
CREATED as created,
|
|
124
|
-
SQL_MODE as sql_mode,
|
|
125
|
-
DEFINER as definer,
|
|
126
|
-
CHARACTER_SET_CLIENT as charset,
|
|
127
|
-
COLLATION_CONNECTION as collation,
|
|
128
|
-
DATABASE_COLLATION as db_collation
|
|
129
|
-
FROM INFORMATION_SCHEMA.TRIGGERS
|
|
130
|
-
WHERE TRIGGER_SCHEMA = ? AND TRIGGER_NAME = ?
|
|
112
|
+
const query = `
|
|
113
|
+
SELECT
|
|
114
|
+
TRIGGER_NAME as trigger_name,
|
|
115
|
+
EVENT_MANIPULATION as event,
|
|
116
|
+
EVENT_OBJECT_SCHEMA as schema_name,
|
|
117
|
+
EVENT_OBJECT_TABLE as table_name,
|
|
118
|
+
ACTION_ORDER as action_order,
|
|
119
|
+
ACTION_CONDITION as condition_value,
|
|
120
|
+
ACTION_STATEMENT as statement,
|
|
121
|
+
ACTION_ORIENTATION as orientation,
|
|
122
|
+
ACTION_TIMING as timing,
|
|
123
|
+
ACTION_REFERENCE_OLD_TABLE as old_table,
|
|
124
|
+
ACTION_REFERENCE_NEW_TABLE as new_table,
|
|
125
|
+
ACTION_REFERENCE_OLD_ROW as old_row,
|
|
126
|
+
ACTION_REFERENCE_NEW_ROW as new_row,
|
|
127
|
+
CREATED as created,
|
|
128
|
+
SQL_MODE as sql_mode,
|
|
129
|
+
DEFINER as definer,
|
|
130
|
+
CHARACTER_SET_CLIENT as charset,
|
|
131
|
+
COLLATION_CONNECTION as collation,
|
|
132
|
+
DATABASE_COLLATION as db_collation
|
|
133
|
+
FROM INFORMATION_SCHEMA.TRIGGERS
|
|
134
|
+
WHERE TRIGGER_SCHEMA = ? AND TRIGGER_NAME = ?
|
|
131
135
|
`;
|
|
132
|
-
const results = await this.db.query(query, [
|
|
136
|
+
const results = await this.db.query(query, [
|
|
137
|
+
database,
|
|
138
|
+
trigger_name,
|
|
139
|
+
]);
|
|
133
140
|
if (results.length === 0) {
|
|
134
141
|
return {
|
|
135
|
-
status:
|
|
142
|
+
status: "error",
|
|
136
143
|
error: `Trigger '${trigger_name}' not found in database '${database}'`,
|
|
137
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
138
144
|
};
|
|
139
145
|
}
|
|
140
146
|
return {
|
|
141
|
-
status:
|
|
147
|
+
status: "success",
|
|
142
148
|
data: results[0],
|
|
143
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
144
149
|
};
|
|
145
150
|
}
|
|
146
151
|
catch (error) {
|
|
147
152
|
return {
|
|
148
|
-
status:
|
|
153
|
+
status: "error",
|
|
149
154
|
error: error.message,
|
|
150
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
151
155
|
};
|
|
152
156
|
}
|
|
153
157
|
}
|
|
@@ -158,30 +162,39 @@ class TriggerTools {
|
|
|
158
162
|
try {
|
|
159
163
|
const dbValidation = this.validateDatabaseAccess(params?.database);
|
|
160
164
|
if (!dbValidation.valid) {
|
|
161
|
-
return { status:
|
|
165
|
+
return { status: "error", error: dbValidation.error };
|
|
162
166
|
}
|
|
163
167
|
const { trigger_name, table_name, timing, event, body, definer } = params;
|
|
164
168
|
const database = dbValidation.database;
|
|
165
169
|
// Validate trigger name
|
|
166
170
|
const triggerValidation = this.security.validateIdentifier(trigger_name);
|
|
167
171
|
if (!triggerValidation.valid) {
|
|
168
|
-
return {
|
|
172
|
+
return {
|
|
173
|
+
status: "error",
|
|
174
|
+
error: triggerValidation.error || "Invalid trigger name",
|
|
175
|
+
};
|
|
169
176
|
}
|
|
170
177
|
// Validate table name
|
|
171
178
|
const tableValidation = this.security.validateIdentifier(table_name);
|
|
172
179
|
if (!tableValidation.valid) {
|
|
173
|
-
return {
|
|
180
|
+
return {
|
|
181
|
+
status: "error",
|
|
182
|
+
error: tableValidation.error || "Invalid table name",
|
|
183
|
+
};
|
|
174
184
|
}
|
|
175
185
|
// Validate timing
|
|
176
|
-
if (![
|
|
177
|
-
return { status:
|
|
186
|
+
if (!["BEFORE", "AFTER"].includes(timing)) {
|
|
187
|
+
return { status: "error", error: "Timing must be BEFORE or AFTER" };
|
|
178
188
|
}
|
|
179
189
|
// Validate event
|
|
180
|
-
if (![
|
|
181
|
-
return {
|
|
190
|
+
if (!["INSERT", "UPDATE", "DELETE"].includes(event)) {
|
|
191
|
+
return {
|
|
192
|
+
status: "error",
|
|
193
|
+
error: "Event must be INSERT, UPDATE, or DELETE",
|
|
194
|
+
};
|
|
182
195
|
}
|
|
183
196
|
// Build CREATE TRIGGER statement
|
|
184
|
-
let createQuery =
|
|
197
|
+
let createQuery = "CREATE";
|
|
185
198
|
if (definer) {
|
|
186
199
|
createQuery += ` DEFINER = ${definer}`;
|
|
187
200
|
}
|
|
@@ -191,7 +204,8 @@ class TriggerTools {
|
|
|
191
204
|
createQuery += ` FOR EACH ROW`;
|
|
192
205
|
// Check if body already contains BEGIN/END
|
|
193
206
|
const trimmedBody = body.trim();
|
|
194
|
-
if (trimmedBody.toUpperCase().startsWith(
|
|
207
|
+
if (trimmedBody.toUpperCase().startsWith("BEGIN") &&
|
|
208
|
+
trimmedBody.toUpperCase().endsWith("END")) {
|
|
195
209
|
createQuery += `\n${body}`;
|
|
196
210
|
}
|
|
197
211
|
else {
|
|
@@ -199,23 +213,21 @@ class TriggerTools {
|
|
|
199
213
|
}
|
|
200
214
|
await this.db.query(createQuery);
|
|
201
215
|
return {
|
|
202
|
-
status:
|
|
216
|
+
status: "success",
|
|
203
217
|
data: {
|
|
204
218
|
message: `Trigger '${trigger_name}' created successfully`,
|
|
205
219
|
trigger_name,
|
|
206
220
|
table_name,
|
|
207
221
|
timing,
|
|
208
222
|
event,
|
|
209
|
-
database
|
|
223
|
+
database,
|
|
210
224
|
},
|
|
211
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
212
225
|
};
|
|
213
226
|
}
|
|
214
227
|
catch (error) {
|
|
215
228
|
return {
|
|
216
|
-
status:
|
|
229
|
+
status: "error",
|
|
217
230
|
error: error.message,
|
|
218
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
219
231
|
};
|
|
220
232
|
}
|
|
221
233
|
}
|
|
@@ -226,28 +238,29 @@ class TriggerTools {
|
|
|
226
238
|
try {
|
|
227
239
|
const dbValidation = this.validateDatabaseAccess(params?.database);
|
|
228
240
|
if (!dbValidation.valid) {
|
|
229
|
-
return { status:
|
|
241
|
+
return { status: "error", error: dbValidation.error };
|
|
230
242
|
}
|
|
231
243
|
const { trigger_name, if_exists = false } = params;
|
|
232
244
|
const database = dbValidation.database;
|
|
233
245
|
// Validate trigger name
|
|
234
246
|
const identifierValidation = this.security.validateIdentifier(trigger_name);
|
|
235
247
|
if (!identifierValidation.valid) {
|
|
236
|
-
return {
|
|
248
|
+
return {
|
|
249
|
+
status: "error",
|
|
250
|
+
error: identifierValidation.error || "Invalid trigger name",
|
|
251
|
+
};
|
|
237
252
|
}
|
|
238
|
-
const dropQuery = `DROP TRIGGER ${if_exists ?
|
|
253
|
+
const dropQuery = `DROP TRIGGER ${if_exists ? "IF EXISTS" : ""} \`${database}\`.\`${trigger_name}\``;
|
|
239
254
|
await this.db.query(dropQuery);
|
|
240
255
|
return {
|
|
241
|
-
status:
|
|
256
|
+
status: "success",
|
|
242
257
|
message: `Trigger '${trigger_name}' dropped successfully`,
|
|
243
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
244
258
|
};
|
|
245
259
|
}
|
|
246
260
|
catch (error) {
|
|
247
261
|
return {
|
|
248
|
-
status:
|
|
262
|
+
status: "error",
|
|
249
263
|
error: error.message,
|
|
250
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
251
264
|
};
|
|
252
265
|
}
|
|
253
266
|
}
|
|
@@ -258,35 +271,35 @@ class TriggerTools {
|
|
|
258
271
|
try {
|
|
259
272
|
const dbValidation = this.validateDatabaseAccess(params?.database);
|
|
260
273
|
if (!dbValidation.valid) {
|
|
261
|
-
return { status:
|
|
274
|
+
return { status: "error", error: dbValidation.error };
|
|
262
275
|
}
|
|
263
276
|
const { trigger_name } = params;
|
|
264
277
|
const database = dbValidation.database;
|
|
265
278
|
// Validate trigger name
|
|
266
279
|
const identifierValidation = this.security.validateIdentifier(trigger_name);
|
|
267
280
|
if (!identifierValidation.valid) {
|
|
268
|
-
return {
|
|
281
|
+
return {
|
|
282
|
+
status: "error",
|
|
283
|
+
error: identifierValidation.error || "Invalid trigger name",
|
|
284
|
+
};
|
|
269
285
|
}
|
|
270
286
|
const query = `SHOW CREATE TRIGGER \`${database}\`.\`${trigger_name}\``;
|
|
271
287
|
const results = await this.db.query(query);
|
|
272
288
|
if (results.length === 0) {
|
|
273
289
|
return {
|
|
274
|
-
status:
|
|
290
|
+
status: "error",
|
|
275
291
|
error: `Trigger '${trigger_name}' not found`,
|
|
276
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
277
292
|
};
|
|
278
293
|
}
|
|
279
294
|
return {
|
|
280
|
-
status:
|
|
295
|
+
status: "success",
|
|
281
296
|
data: results[0],
|
|
282
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
283
297
|
};
|
|
284
298
|
}
|
|
285
299
|
catch (error) {
|
|
286
300
|
return {
|
|
287
|
-
status:
|
|
301
|
+
status: "error",
|
|
288
302
|
error: error.message,
|
|
289
|
-
queryLog: this.db.getFormattedQueryLogs(1)
|
|
290
303
|
};
|
|
291
304
|
}
|
|
292
305
|
}
|
|
@@ -199,14 +199,12 @@ class UtilityTools {
|
|
|
199
199
|
as_parent: parentRelationships,
|
|
200
200
|
as_child: childRelationships,
|
|
201
201
|
},
|
|
202
|
-
queryLog: this.db.getFormattedQueryLogs(2),
|
|
203
202
|
};
|
|
204
203
|
}
|
|
205
204
|
catch (error) {
|
|
206
205
|
return {
|
|
207
206
|
status: "error",
|
|
208
207
|
error: error.message,
|
|
209
|
-
queryLog: this.db.getFormattedQueryLogs(2),
|
|
210
208
|
};
|
|
211
209
|
}
|
|
212
210
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SecurityLayer } from
|
|
1
|
+
import { SecurityLayer } from "../security/securityLayer";
|
|
2
2
|
export declare class ViewTools {
|
|
3
3
|
private db;
|
|
4
4
|
private security;
|
|
@@ -16,7 +16,6 @@ export declare class ViewTools {
|
|
|
16
16
|
status: string;
|
|
17
17
|
data?: any[];
|
|
18
18
|
error?: string;
|
|
19
|
-
queryLog?: string;
|
|
20
19
|
}>;
|
|
21
20
|
/**
|
|
22
21
|
* Get detailed information about a specific view
|
|
@@ -28,7 +27,6 @@ export declare class ViewTools {
|
|
|
28
27
|
status: string;
|
|
29
28
|
data?: any;
|
|
30
29
|
error?: string;
|
|
31
|
-
queryLog?: string;
|
|
32
30
|
}>;
|
|
33
31
|
/**
|
|
34
32
|
* Create a new view
|
|
@@ -37,15 +35,14 @@ export declare class ViewTools {
|
|
|
37
35
|
view_name: string;
|
|
38
36
|
definition: string;
|
|
39
37
|
or_replace?: boolean;
|
|
40
|
-
algorithm?:
|
|
41
|
-
security?:
|
|
42
|
-
check_option?:
|
|
38
|
+
algorithm?: "UNDEFINED" | "MERGE" | "TEMPTABLE";
|
|
39
|
+
security?: "DEFINER" | "INVOKER";
|
|
40
|
+
check_option?: "CASCADED" | "LOCAL";
|
|
43
41
|
database?: string;
|
|
44
42
|
}): Promise<{
|
|
45
43
|
status: string;
|
|
46
44
|
data?: any;
|
|
47
45
|
error?: string;
|
|
48
|
-
queryLog?: string;
|
|
49
46
|
}>;
|
|
50
47
|
/**
|
|
51
48
|
* Alter an existing view
|
|
@@ -53,15 +50,14 @@ export declare class ViewTools {
|
|
|
53
50
|
alterView(params: {
|
|
54
51
|
view_name: string;
|
|
55
52
|
definition: string;
|
|
56
|
-
algorithm?:
|
|
57
|
-
security?:
|
|
58
|
-
check_option?:
|
|
53
|
+
algorithm?: "UNDEFINED" | "MERGE" | "TEMPTABLE";
|
|
54
|
+
security?: "DEFINER" | "INVOKER";
|
|
55
|
+
check_option?: "CASCADED" | "LOCAL";
|
|
59
56
|
database?: string;
|
|
60
57
|
}): Promise<{
|
|
61
58
|
status: string;
|
|
62
59
|
data?: any;
|
|
63
60
|
error?: string;
|
|
64
|
-
queryLog?: string;
|
|
65
61
|
}>;
|
|
66
62
|
/**
|
|
67
63
|
* Drop a view
|
|
@@ -74,7 +70,6 @@ export declare class ViewTools {
|
|
|
74
70
|
status: string;
|
|
75
71
|
message?: string;
|
|
76
72
|
error?: string;
|
|
77
|
-
queryLog?: string;
|
|
78
73
|
}>;
|
|
79
74
|
/**
|
|
80
75
|
* Show the CREATE statement for a view
|
|
@@ -86,6 +81,5 @@ export declare class ViewTools {
|
|
|
86
81
|
status: string;
|
|
87
82
|
data?: any;
|
|
88
83
|
error?: string;
|
|
89
|
-
queryLog?: string;
|
|
90
84
|
}>;
|
|
91
85
|
}
|