2020-09-25 12:39:58 +02:00
|
|
|
|
|
|
|
import { ipcMain } from 'electron';
|
|
|
|
|
|
|
|
export default connections => {
|
2021-03-17 11:15:14 +01:00
|
|
|
ipcMain.handle('create-schema', async (event, params) => {
|
2020-09-25 12:39:58 +02:00
|
|
|
try {
|
2021-03-17 11:15:14 +01:00
|
|
|
await connections[params.uid].createSchema(params);
|
2020-09-25 12:39:58 +02:00
|
|
|
|
2020-09-29 16:43:20 +02:00
|
|
|
return { status: 'success' };
|
2020-09-25 12:39:58 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-17 11:15:14 +01:00
|
|
|
ipcMain.handle('update-schema', async (event, params) => {
|
2020-10-03 12:11:42 +02:00
|
|
|
try {
|
2021-03-17 11:15:14 +01:00
|
|
|
await connections[params.uid].alterSchema(params);
|
2020-10-03 12:11:42 +02:00
|
|
|
|
|
|
|
return { status: 'success' };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-17 11:15:14 +01:00
|
|
|
ipcMain.handle('delete-schema', async (event, params) => {
|
2020-10-01 15:08:35 +02:00
|
|
|
try {
|
2021-03-17 11:15:14 +01:00
|
|
|
await connections[params.uid].dropSchema(params);
|
2020-10-01 15:08:35 +02:00
|
|
|
|
|
|
|
return { status: 'success' };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-17 11:15:14 +01:00
|
|
|
ipcMain.handle('get-schema-collation', async (event, params) => {
|
2020-10-03 12:11:42 +02:00
|
|
|
try {
|
2021-03-16 18:42:03 +01:00
|
|
|
const collation = await connections[params.uid].getDatabaseCollation(params);
|
2020-10-03 12:11:42 +02:00
|
|
|
|
|
|
|
return { status: 'success', response: collation.rows.length ? collation.rows[0].DEFAULT_COLLATION_NAME : '' };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-23 15:50:21 +01:00
|
|
|
ipcMain.handle('get-structure', async (event, params) => {
|
2020-09-25 12:39:58 +02:00
|
|
|
try {
|
2021-01-23 15:50:21 +01:00
|
|
|
const structure = await connections[params.uid].getStructure(params.schemas);
|
2020-09-25 12:39:58 +02:00
|
|
|
|
|
|
|
return { status: 'success', response: structure };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.handle('get-collations', async (event, uid) => {
|
|
|
|
try {
|
|
|
|
const result = await connections[uid].getCollations();
|
|
|
|
|
|
|
|
return { status: 'success', response: result };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.handle('get-variables', async (event, uid) => {
|
|
|
|
try {
|
|
|
|
const result = await connections[uid].getVariables();
|
|
|
|
|
|
|
|
return { status: 'success', response: result };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-11-16 17:16:39 +01:00
|
|
|
ipcMain.handle('get-engines', async (event, uid) => {
|
|
|
|
try {
|
|
|
|
const result = await connections[uid].getEngines();
|
|
|
|
|
|
|
|
return { status: 'success', response: result };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-02-01 16:31:48 +01:00
|
|
|
ipcMain.handle('get-version', async (event, uid) => {
|
|
|
|
try {
|
|
|
|
const result = await connections[uid].getVersion();
|
|
|
|
|
|
|
|
return { status: 'success', response: result };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-03 19:31:05 +01:00
|
|
|
ipcMain.handle('get-processes', async (event, uid) => {
|
|
|
|
try {
|
|
|
|
const result = await connections[uid].getProcesses();
|
|
|
|
|
|
|
|
return { status: 'success', response: result };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-26 11:19:48 +02:00
|
|
|
ipcMain.handle('kill-process', async (event, { uid, pid }) => {
|
|
|
|
try {
|
|
|
|
const result = await connections[uid].killProcess(pid);
|
|
|
|
|
|
|
|
return { status: 'success', response: result };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-09-29 16:43:20 +02:00
|
|
|
ipcMain.handle('use-schema', async (event, { uid, schema }) => {
|
|
|
|
if (!schema) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
await connections[uid].use(schema);
|
|
|
|
return { status: 'success' };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-09-25 12:39:58 +02:00
|
|
|
ipcMain.handle('raw-query', async (event, { uid, query, schema }) => {
|
|
|
|
if (!query) return;
|
|
|
|
|
|
|
|
try {
|
2021-07-21 14:40:29 +02:00
|
|
|
const result = await connections[uid].raw(query, {
|
|
|
|
nest: true,
|
|
|
|
details: true,
|
|
|
|
schema,
|
|
|
|
comments: false
|
|
|
|
});
|
2020-09-25 12:39:58 +02:00
|
|
|
|
|
|
|
return { status: 'success', response: result };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|