mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
Partial implementation of fields edit
This commit is contained in:
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
|
|||||||
liberapay: # Replace with a single Liberapay username
|
liberapay: # Replace with a single Liberapay username
|
||||||
issuehunt: # Replace with a single IssueHunt username
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
otechie: # Replace with a single Otechie username
|
otechie: # Replace with a single Otechie username
|
||||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
custom: ['https://paypal.me/fabiodistasio']
|
@ -4,7 +4,7 @@
|
|||||||
"version": "0.0.1-alpha",
|
"version": "0.0.1-alpha",
|
||||||
"description": "A cross-platform easy to use SQL client.",
|
"description": "A cross-platform easy to use SQL client.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "https://github.com/Fabio286/antares.git",
|
"repository": "https://github.com/EStarium/antares.git",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "cross-env NODE_ENV=development electron-webpack dev",
|
"dev": "cross-env NODE_ENV=development electron-webpack dev",
|
||||||
"compile": "electron-webpack",
|
"compile": "electron-webpack",
|
||||||
|
@ -24,4 +24,14 @@ export default (connections) => {
|
|||||||
return { status: 'error', response: err.toString() };
|
return { status: 'error', response: err.toString() };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('updateTableCell', async (event, params) => {
|
||||||
|
try {
|
||||||
|
const result = await Generic.updateTableCell(connections[params.uid], params);
|
||||||
|
return { status: 'success', response: result };
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return { status: 'error', response: err.toString() };
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@ -145,6 +145,11 @@ export class AntaresConnector {
|
|||||||
return this.raw(sql);
|
return this.raw(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update (...args) {
|
||||||
|
this._query.update = [...this._query.update, ...args];
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string} SQL string
|
* @returns {string} SQL string
|
||||||
* @memberof AntaresConnector
|
* @memberof AntaresConnector
|
||||||
@ -152,30 +157,35 @@ export class AntaresConnector {
|
|||||||
getSQL () {
|
getSQL () {
|
||||||
// SELECT
|
// SELECT
|
||||||
const selectArray = this._query.select.reduce(this._reducer, []);
|
const selectArray = this._query.select.reduce(this._reducer, []);
|
||||||
let selectRaw;
|
let selectRaw = '';
|
||||||
switch (this._client) {
|
if (selectArray.length) {
|
||||||
case 'maria':
|
switch (this._client) {
|
||||||
case 'mysql':
|
case 'maria':
|
||||||
selectRaw = selectArray.length ? `SELECT ${selectArray.join(', ')} ` : 'SELECT * ';
|
case 'mysql':
|
||||||
break;
|
selectRaw = selectArray.length ? `SELECT ${selectArray.join(', ')} ` : 'SELECT * ';
|
||||||
case 'mssql': {
|
break;
|
||||||
const topRaw = this._query.limit.length ? ` TOP (${this._query.limit[0]}) ` : '';
|
case 'mssql': {
|
||||||
selectRaw = selectArray.length ? `SELECT${topRaw} ${selectArray.join(', ')} ` : 'SELECT * ';
|
const topRaw = this._query.limit.length ? ` TOP (${this._query.limit[0]}) ` : '';
|
||||||
|
selectRaw = selectArray.length ? `SELECT${topRaw} ${selectArray.join(', ')} ` : 'SELECT * ';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FROM
|
// FROM
|
||||||
let fromRaw;
|
let fromRaw = '';
|
||||||
|
if (!this._query.update.length)
|
||||||
|
fromRaw = 'FROM';
|
||||||
|
|
||||||
switch (this._client) {
|
switch (this._client) {
|
||||||
case 'maria':
|
case 'maria':
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
fromRaw = this._query.from ? `FROM ${this._query.schema ? `\`${this._query.schema}\`.` : ''}\`${this._query.from}\` ` : '';
|
fromRaw += this._query.from ? ` ${this._query.schema ? `\`${this._query.schema}\`.` : ''}\`${this._query.from}\` ` : '';
|
||||||
break;
|
break;
|
||||||
case 'mssql':
|
case 'mssql':
|
||||||
fromRaw = this._query.from ? `FROM ${this._query.schema ? `${this._query.schema}.` : ''}${this._query.from} ` : '';
|
fromRaw += this._query.from ? ` ${this._query.schema ? `${this._query.schema}.` : ''}${this._query.from} ` : '';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -183,8 +193,13 @@ export class AntaresConnector {
|
|||||||
|
|
||||||
const whereArray = this._query.where.reduce(this._reducer, []);
|
const whereArray = this._query.where.reduce(this._reducer, []);
|
||||||
const whereRaw = whereArray.length ? `WHERE ${whereArray.join(' AND ')} ` : '';
|
const whereRaw = whereArray.length ? `WHERE ${whereArray.join(' AND ')} ` : '';
|
||||||
|
|
||||||
|
const updateArray = this._query.update.reduce(this._reducer, []);
|
||||||
|
const updateRaw = updateArray.length ? `SET ${updateArray.join(', ')} ` : '';
|
||||||
|
|
||||||
const groupByArray = this._query.groupBy.reduce(this._reducer, []);
|
const groupByArray = this._query.groupBy.reduce(this._reducer, []);
|
||||||
const groupByRaw = groupByArray.length ? `GROUP BY ${groupByArray.join(', ')} ` : '';
|
const groupByRaw = groupByArray.length ? `GROUP BY ${groupByArray.join(', ')} ` : '';
|
||||||
|
|
||||||
const orderByArray = this._query.orderBy.reduce(this._reducer, []);
|
const orderByArray = this._query.orderBy.reduce(this._reducer, []);
|
||||||
const orderByRaw = orderByArray.length ? `ORDER BY ${orderByArray.join(', ')} ` : '';
|
const orderByRaw = orderByArray.length ? `ORDER BY ${orderByArray.join(', ')} ` : '';
|
||||||
|
|
||||||
@ -202,7 +217,7 @@ export class AntaresConnector {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${selectRaw}${fromRaw}${whereRaw}${groupByRaw}${orderByRaw}${limitRaw}`;
|
return `${selectRaw}${updateRaw ? 'UPDATE' : ''}${fromRaw}${updateRaw}${whereRaw}${groupByRaw}${orderByRaw}${limitRaw}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,4 +20,13 @@ export default class {
|
|||||||
.limit(1000)
|
.limit(1000)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async updateTableCell (connection, params) { // TODO: Handle different field types
|
||||||
|
return connection
|
||||||
|
.update({ [params.field]: `= "${params.content}"` })
|
||||||
|
.schema(params.schema)
|
||||||
|
.from(params.table)
|
||||||
|
.where({ [params.primary]: `= ${params.id}` })
|
||||||
|
.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@
|
|||||||
<h4>{{ appName }}</h4>
|
<h4>{{ appName }}</h4>
|
||||||
<p>
|
<p>
|
||||||
{{ $t('word.version') }}: {{ appVersion }}<br>
|
{{ $t('word.version') }}: {{ appVersion }}<br>
|
||||||
<a class="c-hand" @click="openOutside('https://github.com/Fabio286/antares')">GitHub</a><br>
|
<a class="c-hand" @click="openOutside('https://github.com/EStarium/antares')">GitHub</a><br>
|
||||||
<small>{{ $t('message.madeWithJS') }}</small>
|
<small>{{ $t('message.madeWithJS') }}</small>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
<div class="footer-right-elements">
|
<div class="footer-right-elements">
|
||||||
<ul class="footer-elements">
|
<ul class="footer-elements">
|
||||||
<li class="footer-element footer-link">
|
<li class="footer-element footer-link" @click="openOutside('https://www.patreon.com/fabio286')">
|
||||||
<i class="material-icons md-18 mr-1">favorite</i>
|
<i class="material-icons md-18 mr-1">favorite</i>
|
||||||
<small>{{ $t('word.donate') }}</small>
|
<small>{{ $t('word.donate') }}</small>
|
||||||
</li>
|
</li>
|
||||||
<li class="footer-element footer-link">
|
<li class="footer-element footer-link" @click="openOutside('https://github.com/EStarium/antares/issues')">
|
||||||
<i class="material-icons md-18">bug_report</i>
|
<i class="material-icons md-18">bug_report</i>
|
||||||
</li>
|
</li>
|
||||||
<li class="footer-element footer-link" @click="showSettingModal('about')">
|
<li class="footer-element footer-link" @click="showSettingModal('about')">
|
||||||
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapActions, mapGetters } from 'vuex';
|
import { mapActions, mapGetters } from 'vuex';
|
||||||
|
const { shell } = require('electron');
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'TheFooter',
|
name: 'TheFooter',
|
||||||
@ -40,7 +41,10 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
...mapActions({
|
...mapActions({
|
||||||
showSettingModal: 'application/showSettingModal'
|
showSettingModal: 'application/showSettingModal'
|
||||||
})
|
}),
|
||||||
|
openOutside (link) {
|
||||||
|
shell.openExternal(link);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
:content="col"
|
:content="col"
|
||||||
:field="cKey"
|
:field="cKey"
|
||||||
:type="fieldType(cKey)"
|
:type="fieldType(cKey)"
|
||||||
@updateField="updateField"
|
@updateField="updateField($event, row[primaryField.name])"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -128,10 +128,17 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateField (payload) {
|
updateField (event, id) {
|
||||||
if (!this.primaryField)
|
if (!this.primaryField)
|
||||||
this.addNotification({ status: 'warning', message: this.$t('message.unableEditFieldWithoutPrimary') });
|
this.addNotification({ status: 'warning', message: this.$t('message.unableEditFieldWithoutPrimary') });
|
||||||
console.log(payload);
|
else {
|
||||||
|
const params = {
|
||||||
|
primary: this.primaryField.name,
|
||||||
|
id,
|
||||||
|
...event
|
||||||
|
};
|
||||||
|
this.$emit('updateField', params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -120,8 +120,8 @@ export default {
|
|||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
if (this.localContent === this.content) return;
|
if (this.localContent === this.content) return;
|
||||||
|
|
||||||
const { field, localContent: content } = this;
|
const { field, type, localContent: content } = this;
|
||||||
this.$emit('updateField', { field, content });
|
this.$emit('updateField', { field, type, content });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
v-if="results"
|
v-if="results"
|
||||||
:results="results"
|
:results="results"
|
||||||
:fields="resultsFields"
|
:fields="resultsFields"
|
||||||
|
@updateField="updateField"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -134,6 +135,24 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.isQuering = false;
|
this.isQuering = false;
|
||||||
|
},
|
||||||
|
async updateField (payload) {
|
||||||
|
const params = {
|
||||||
|
uid: this.connection.uid,
|
||||||
|
schema: this.workspace.breadcrumbs.schema,
|
||||||
|
table: this.workspace.breadcrumbs.table,
|
||||||
|
...payload
|
||||||
|
};
|
||||||
|
console.log(params);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { status, response } = await Structure.updateTableCell(params);
|
||||||
|
if (status !== 'success')
|
||||||
|
this.addNotification({ status: 'error', message: response });
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
this.addNotification({ status: 'error', message: err.stack });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -9,4 +9,8 @@ export default class {
|
|||||||
static getTableData (params) {
|
static getTableData (params) {
|
||||||
return ipcRenderer.invoke('getTableData', params);
|
return ipcRenderer.invoke('getTableData', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static updateTableCell (params) {
|
||||||
|
return ipcRenderer.invoke('updateTableCell', params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user