2020-09-25 12:39:58 +02:00
|
|
|
|
|
|
|
import { ipcMain } from 'electron';
|
|
|
|
|
|
|
|
export default connections => {
|
|
|
|
ipcMain.handle('create-database', async (event, params) => {
|
|
|
|
try {
|
|
|
|
const query = `CREATE DATABASE \`${params.name}\` COLLATE ${params.collation}`;
|
|
|
|
const result = await connections[params.uid].raw(query, true);
|
|
|
|
|
|
|
|
return { status: 'success', response: result };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.handle('get-structure', async (event, uid) => {
|
|
|
|
try {
|
2020-09-27 19:06:13 +02:00
|
|
|
const structure = await connections[uid].getStructure();
|
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() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.handle('raw-query', async (event, { uid, query, schema }) => {
|
|
|
|
if (!query) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (schema)
|
|
|
|
await connections[uid].use(schema);
|
|
|
|
|
|
|
|
const result = await connections[uid].raw(query, true);
|
|
|
|
|
|
|
|
return { status: 'success', response: result };
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { status: 'error', response: err.toString() };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|