Skip to content

Commit

Permalink
feat: support to multiple queries in the same tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Sep 6, 2020
1 parent 3385744 commit 48f77ba
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 104 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@
"monaco-editor": "^0.20.0",
"mssql": "^6.2.1",
"mysql": "^2.18.1",
"pg": "^8.3.2",
"pg": "^8.3.3",
"source-map-support": "^0.5.16",
"spectre.css": "^0.5.9",
"vue-click-outside": "^1.1.0",
"vue-i18n": "^8.21.0",
"vue-the-mask": "^0.11.1",
"vuedraggable": "^2.24.0",
"vuedraggable": "^2.24.1",
"vuex": "^3.5.1",
"vuex-persist": "^2.2.0"
},
Expand All @@ -71,7 +71,7 @@
"electron-devtools-installer": "^3.1.1",
"electron-webpack": "^2.8.2",
"electron-webpack-vue": "^2.4.0",
"eslint": "^7.7.0",
"eslint": "^7.8.1",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
Expand All @@ -80,12 +80,12 @@
"eslint-plugin-vue": "^6.2.2",
"monaco-editor-webpack-plugin": "^1.9.0",
"node-sass": "^4.14.1",
"sass-loader": "^10.0.1",
"sass-loader": "^10.0.2",
"standard-version": "^9.0.0",
"stylelint": "^13.6.1",
"stylelint": "^13.7.0",
"stylelint-config-standard": "^20.0.0",
"stylelint-scss": "^3.18.0",
"vue": "^2.6.11",
"vue": "^2.6.12",
"webpack": "^4.44.1"
}
}
55 changes: 33 additions & 22 deletions src/main/libs/AntaresConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,33 +280,44 @@ export class AntaresConnector {
* @memberof AntaresConnector
*/
async raw (sql) {
const resultsArr = [];
const queries = sql.split(';');

if (process.env.NODE_ENV === 'development') this._logger(sql);// TODO: replace BLOB content with a placeholder

switch (this._client) { // TODO: uniform fields with every client type, needed table name and fields array
case 'maria':
case 'mysql': {
const { rows, report, fields } = await new Promise((resolve, reject) => {
this._connection.query(sql, (err, response, fields) => {
if (err)
reject(err);
else {
resolve({
rows: Array.isArray(response) ? response : false,
report: !Array.isArray(response) ? response : false,
fields
});
}
for (const query of queries) {
if (!query) continue;

switch (this._client) { // TODO: uniform fields with every client type, needed table name and fields array
case 'maria':
case 'mysql': {
const { rows, report, fields } = await new Promise((resolve, reject) => {
this._connection.query(query, (err, response, fields) => {
if (err)
reject(err);
else {
resolve({
rows: Array.isArray(response) ? response : false,
report: !Array.isArray(response) ? response : false,
fields
});
}
});
});
});
return { rows, report, fields };
}
case 'mssql': {
const results = await this._connection.request().query(sql);
return { rows: results.recordsets[0] };// TODO: fields
resultsArr.push({ rows, report, fields });
break;
}
case 'mssql': {
const results = await this._connection.request().query(query);
resultsArr.push({ rows: results.recordsets[0] });// TODO: fields
break;
}
default:
break;
}
default:
break;
}

return resultsArr.length === 1 ? resultsArr[0] : resultsArr;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/Workspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
</a>
</li>
</ul>
<div v-show="selectedTab === 'prop'" class="column col-12">
<p class="px-2">
In future releases
</p>
</div>
<WorkspaceTableTab
v-show="selectedTab === 'data'"
:connection="connection"
Expand Down
127 changes: 72 additions & 55 deletions src/renderer/components/WorkspaceQueryTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
</button>
</div>
<div class="workspace-query-info">
<div v-if="results.rows">
{{ $t('word.results') }}: <b>{{ results.rows.length }}</b>
<div v-if="results[selectedResultsset] && results[selectedResultsset].rows">
{{ $t('word.results') }}: <b>{{ resultsCount }}</b>
</div>
<div v-if="results.report">
{{ $t('message.affectedRows') }}: <b>{{ results.report.affectedRows }}</b>
<div v-if="results[selectedResultsset] && results[selectedResultsset].report">
{{ $t('message.affectedRows') }}: <b>{{ affectedCount }}</b>
</div>
<div v-if="workspace.breadcrumbs.schema">
{{ $t('word.schema') }}: <b>{{ workspace.breadcrumbs.schema }}</b>
Expand Down Expand Up @@ -66,8 +66,10 @@ export default {
query: '',
lastQuery: '',
isQuering: false,
results: {},
selectedFields: []
results: [],
resultsCount: 0,
affectedCount: 0,
selectedResultsset: 0
};
},
computed: {
Expand All @@ -77,11 +79,6 @@ export default {
workspace () {
return this.getWorkspace(this.connection.uid);
},
table () {
if ('fields' in this.results && this.results.fields.length)
return this.results.fields[0].orgTable;
return '';
},
schema () {
if ('fields' in this.results && this.results.fields.length)
return this.results.fields[0].db;
Expand All @@ -94,6 +91,11 @@ export default {
setTabFields: 'workspaces/setTabFields',
setTabKeyUsage: 'workspaces/setTabKeyUsage'
}),
getTable (index) {
if ('fields' in this.results[index] && this.results[index].fields.length)
return this.results[index].fields[0].orgTable;
return '';
},
async runQuery (query) {
if (!query) return;
this.isQuering = true;
Expand All @@ -107,56 +109,69 @@ export default {
};
const { status, response } = await Connection.rawQuery(params);
if (status === 'success') {
this.results = response;
if (response.rows) { // if is a select
this.selectedFields = response.fields.map(field => field.orgName);
try { // Table data
const params = {
uid: this.connection.uid,
schema: this.schema,
table: this.table
};
const { status, response } = await Tables.getTableColumns(params);
if (status === 'success') {
let fields = response.filter(field => this.selectedFields.includes(field.name));
if (this.selectedFields.length) {
fields = fields.map((field, index) => {
return { ...field, alias: this.results.fields[index].name };
});
this.results = Array.isArray(response) ? response : [response];
let selectedFields = [];
const fieldsArr = [];
const keysArr = [];
for (const [index, result] of this.results.entries()) {
if (result.rows) { // if is a select
selectedFields = result.fields.map(field => field.orgName);
this.resultsCount += result.rows.length;
try { // Table data
const params = {
uid: this.connection.uid,
schema: this.schema,
table: this.getTable(index)
};
const { status, response } = await Tables.getTableColumns(params);
if (status === 'success') {
let fields = response.filter(field => selectedFields.includes(field.name));
if (selectedFields.length) {
fields = fields.map((field, index) => {
return { ...field, alias: result.fields[index].name };
});
}
fieldsArr.push(fields);
}
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields });
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
try { // Key usage (foreign keys)
const params = {
uid: this.connection.uid,
schema: this.schema,
table: this.table
};
const { status, response } = await Tables.getKeyUsage(params);
if (status === 'success')
this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: response });
else
this.addNotification({ status: 'error', message: response });
try { // Key usage (foreign keys)
const params = {
uid: this.connection.uid,
schema: this.schema,
table: this.getTable(index)
};
const { status, response } = await Tables.getKeyUsage(params);
if (status === 'success')
keysArr.push(response);
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
else { // if is a query without results
this.affectedCount += result.report.affectedRows;
}
}
else { // if is a query without results
}
console.log(fieldsArr);
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: fieldsArr });
this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: keysArr });
}
else
this.addNotification({ status: 'error', message: response });
Expand All @@ -172,7 +187,9 @@ export default {
this.runQuery(this.lastQuery);
},
clearTabData () {
this.results = {};
this.results = [];
this.resultsCount = 0;
this.affectedCount = 0;
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: [] });
}
}
Expand Down
Loading

0 comments on commit 48f77ba

Please sign in to comment.