-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
311 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
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 { | ||
const { rows: structure } = await connections[uid] | ||
.select('*') | ||
.schema('information_schema') | ||
.from('TABLES') | ||
.orderBy({ TABLE_SCHEMA: 'ASC', TABLE_NAME: 'ASC' }) | ||
.run(); | ||
|
||
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() }; | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<template> | ||
<div class="modal active"> | ||
<a class="modal-overlay" @click.stop="closeModal" /> | ||
<div class="modal-container p-0"> | ||
<div class="modal-header pl-2"> | ||
<div class="modal-title h6"> | ||
<div class="d-flex"> | ||
<i class="mdi mdi-24px mdi-database-plus mr-1" /> {{ $t('message.createNewDatabase') }} | ||
</div> | ||
</div> | ||
<a class="btn btn-clear c-hand" @click.stop="closeModal" /> | ||
</div> | ||
<div class="modal-body pb-0"> | ||
<div class="content"> | ||
<form class="form-horizontal"> | ||
<div class="form-group"> | ||
<div class="col-3"> | ||
<label class="form-label">{{ $t('word.name') }}:</label> | ||
</div> | ||
<div class="col-9"> | ||
<input | ||
v-model="database.name" | ||
class="form-input" | ||
type="text" | ||
required | ||
:placeholder="$t('message.databaseName')" | ||
> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<div class="col-3"> | ||
<label class="form-label">{{ $t('word.collation') }}:</label> | ||
</div> | ||
<div class="col-9"> | ||
<select v-model="database.collation" class="form-select"> | ||
<option | ||
v-for="collation in collations" | ||
:key="collation.id" | ||
:value="collation.collation" | ||
> | ||
{{ collation.collation }} | ||
</option> | ||
</select> | ||
<small>{{ $t('message.serverDefault') }}: {{ defaultCollation }}</small> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
<div class="modal-footer text-light"> | ||
<button class="btn btn-primary mr-2" @click.stop="createDatabase"> | ||
{{ $t('word.add') }} | ||
</button> | ||
<button class="btn btn-link" @click.stop="closeModal"> | ||
{{ $t('word.close') }} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapGetters, mapActions } from 'vuex'; | ||
import Database from '@/ipc-api/Database'; | ||
export default { | ||
name: 'ModalNewDB', | ||
data () { | ||
return { | ||
database: { | ||
name: '', | ||
collation: '' | ||
} | ||
}; | ||
}, | ||
computed: { | ||
...mapGetters({ | ||
selectedWorkspace: 'workspaces/getSelected', | ||
getWorkspace: 'workspaces/getWorkspace', | ||
getDatabaseVariable: 'workspaces/getDatabaseVariable' | ||
}), | ||
collations () { | ||
return this.getWorkspace(this.selectedWorkspace).collations; | ||
}, | ||
defaultCollation () { | ||
return this.getDatabaseVariable(this.selectedWorkspace, 'collation_server').value || ''; | ||
} | ||
}, | ||
created () { | ||
this.database = { ...this.database, collation: this.defaultCollation }; | ||
}, | ||
methods: { | ||
...mapActions({ | ||
addNotification: 'notifications/addNotification' | ||
}), | ||
async createDatabase () { | ||
try { | ||
const { status, response } = await Database.createDatabase({ | ||
uid: this.selectedWorkspace, | ||
...this.database | ||
}); | ||
if (status === 'success') { | ||
this.closeModal(); | ||
this.$emit('reload'); | ||
} | ||
else | ||
this.addNotification({ status: 'error', message: response }); | ||
} | ||
catch (err) { | ||
this.addNotification({ status: 'error', message: err.stack }); | ||
} | ||
}, | ||
closeModal () { | ||
this.$emit('close'); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
.modal-container { | ||
max-width: 360px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.