Skip to content

Commit

Permalink
feat: index management
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Dec 1, 2020
1 parent 8ebc3bc commit 41505bd
Show file tree
Hide file tree
Showing 14 changed files with 550 additions and 41 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.9",
"description": "A cross-platform easy to use SQL client.",
"license": "MIT",
"repository": "https://github.com/EStarium/antares.git",
"repository": "https://github.com/Fabio286/antares.git",
"scripts": {
"dev": "cross-env NODE_ENV=development electron-webpack dev",
"compile": "electron-webpack",
Expand All @@ -17,7 +17,7 @@
},
"author": "Fabio Di Stasio <[email protected]>",
"build": {
"appId": "com.estarium.antares",
"appId": "com.fabio286.antares",
"artifactName": "${productName}-${version}-${os}_${arch}.${ext}",
"dmg": {
"contents": [
Expand Down Expand Up @@ -58,10 +58,10 @@
"pg": "^8.5.1",
"source-map-support": "^0.5.16",
"spectre.css": "^0.5.9",
"vue-i18n": "^8.22.1",
"vue-i18n": "^8.22.2",
"vue-the-mask": "^0.11.1",
"vuedraggable": "^2.24.3",
"vuex": "^3.5.1",
"vuex": "^3.6.0",
"vuex-persist": "^3.1.3"
},
"devDependencies": {
Expand All @@ -72,8 +72,8 @@
"electron-devtools-installer": "^3.1.1",
"electron-webpack": "^2.8.2",
"electron-webpack-vue": "^2.4.0",
"eslint": "^7.13.0",
"eslint-config-standard": "^16.0.1",
"eslint": "^7.14.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
Expand All @@ -82,7 +82,7 @@
"node-sass": "^5.0.0",
"sass-loader": "^10.1.0",
"standard-version": "^9.0.0",
"stylelint": "^13.7.2",
"stylelint": "^13.8.0",
"stylelint-config-standard": "^20.0.0",
"stylelint-scss": "^3.18.0",
"vue": "^2.6.12",
Expand Down
6 changes: 6 additions & 0 deletions src/common/index-types/mysql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = [
'PRIMARY',
'INDEX',
'UNIQUE',
'FULLTEXT'
];
52 changes: 49 additions & 3 deletions src/main/libs/clients/MySQLClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,12 @@ export class MySQLClient extends AntaresCore {
additions,
deletions,
changes,
indexChanges,
options
} = params;

console.log(params);

let sql = `ALTER TABLE \`${table}\` `;
const alterColumns = [];

Expand All @@ -337,7 +340,7 @@ export class MySQLClient extends AntaresCore {
if ('autoIncrement' in options) alterColumns.push(`AUTO_INCREMENT=${+options.autoIncrement}`);
if ('collation' in options) alterColumns.push(`COLLATE='${options.collation}'`);

// ADD
// ADD FIELDS
additions.forEach(addition => {
const length = addition.numLength || addition.charLength || addition.datePrecision;

Expand All @@ -354,7 +357,22 @@ export class MySQLClient extends AntaresCore {
${addition.after ? `AFTER \`${addition.after}\`` : 'FIRST'}`);
});

// CHANGE
// ADD INDEX
indexChanges.additions.forEach(addition => {
const fields = addition.fields.map(field => `\`${field}\``).join(',');
let type = addition.type;

if (type === 'PRIMARY')
alterColumns.push(`ADD PRIMARY KEY (${fields})`);
else {
if (type === 'UNIQUE')
type = 'UNIQUE INDEX';

alterColumns.push(`ADD ${type} \`${addition.name}\` (${fields})`);
}
});

// CHANGE FIELDS
changes.forEach(change => {
const length = change.numLength || change.charLength || change.datePrecision;

Expand All @@ -371,11 +389,39 @@ export class MySQLClient extends AntaresCore {
${change.after ? `AFTER \`${change.after}\`` : 'FIRST'}`);
});

// DROP
// CHANGE INDEX
indexChanges.changes.forEach(change => {
if (change.oldType === 'PRIMARY')
alterColumns.push('DROP PRIMARY KEY');
else
alterColumns.push(`DROP INDEX \`${change.oldName}\``);

const fields = change.fields.map(field => `\`${field}\``).join(',');
let type = change.type;

if (type === 'PRIMARY')
alterColumns.push(`ADD PRIMARY KEY (${fields})`);
else {
if (type === 'UNIQUE')
type = 'UNIQUE INDEX';

alterColumns.push(`ADD ${type} \`${change.name}\` (${fields})`);
}
});

// DROP FIELDS
deletions.forEach(deletion => {
alterColumns.push(`DROP COLUMN \`${deletion.name}\``);
});

// DROP INDEX
indexChanges.deletions.forEach(deletion => {
if (deletion.type === 'PRIMARY')
alterColumns.push('DROP PRIMARY KEY');
else
alterColumns.push(`DROP INDEX \`${deletion.name}\``);
});

sql += alterColumns.join(', ');

// RENAME
Expand Down
22 changes: 20 additions & 2 deletions src/renderer/components/BaseContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ export default {
.context-container {
min-width: 100px;
max-width: 150px;
z-index: 10;
box-shadow: 0 0 1px 0 #000;
box-shadow: 0 0 2px 0 #000;
padding: 0;
background: #1d1d1d;
border-radius: 0.1rem;
Expand All @@ -103,9 +102,28 @@ export default {
padding: 0.1rem 0.3rem;
cursor: pointer;
justify-content: space-between;
position: relative;
.context-submenu {
opacity: 0;
visibility: hidden;
transition: opacity 0.2s;
position: absolute;
left: 100%;
top: 0;
background: #1d1d1d;
box-shadow: 0 0 2px 0 #000;
min-width: 100px;
}
&:hover {
background: $primary-color;
.context-submenu {
display: block;
visibility: visible;
opacity: 1;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<div class="context-element">
<span class="d-flex"><i class="mdi mdi-18px mdi-plus text-light pr-1" /> {{ $t('word.add') }}</span>
<i class="mdi mdi-18px mdi-chevron-right text-light pl-1" />
<div class="context-submenu">
<div class="context-element">
<span class="d-flex"><i class="mdi mdi-18px mdi-table text-light pr-1" /> {{ $t('word.table') }}</span>
</div>
</div>
</div>
<div class="context-element" @click="showEditModal">
<span class="d-flex"><i class="mdi mdi-18px mdi-pencil text-light pr-1" /> {{ $t('word.edit') }}</span>
Expand Down
Loading

0 comments on commit 41505bd

Please sign in to comment.