diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 6fdc131d..ef4b6a43 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt 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'] \ No newline at end of file diff --git a/package.json b/package.json index 7783e8ff..2de52943 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "0.0.1-alpha", "description": "A cross-platform easy to use SQL client.", "license": "MIT", - "repository": "https://github.com/Fabio286/antares.git", + "repository": "https://github.com/EStarium/antares.git", "scripts": { "dev": "cross-env NODE_ENV=development electron-webpack dev", "compile": "electron-webpack", diff --git a/src/main/ipc-handlers/structure.js b/src/main/ipc-handlers/structure.js index fb6a14dc..fc7f4078 100644 --- a/src/main/ipc-handlers/structure.js +++ b/src/main/ipc-handlers/structure.js @@ -24,4 +24,14 @@ export default (connections) => { 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() }; + } + }); }; diff --git a/src/main/libs/AntaresConnector.js b/src/main/libs/AntaresConnector.js index 2d03ec70..2305eda9 100644 --- a/src/main/libs/AntaresConnector.js +++ b/src/main/libs/AntaresConnector.js @@ -145,6 +145,11 @@ export class AntaresConnector { return this.raw(sql); } + update (...args) { + this._query.update = [...this._query.update, ...args]; + return this; + } + /** * @returns {string} SQL string * @memberof AntaresConnector @@ -152,30 +157,35 @@ export class AntaresConnector { getSQL () { // SELECT const selectArray = this._query.select.reduce(this._reducer, []); - let selectRaw; - switch (this._client) { - case 'maria': - case 'mysql': - selectRaw = selectArray.length ? `SELECT ${selectArray.join(', ')} ` : 'SELECT * '; - break; - case 'mssql': { - const topRaw = this._query.limit.length ? ` TOP (${this._query.limit[0]}) ` : ''; - selectRaw = selectArray.length ? `SELECT${topRaw} ${selectArray.join(', ')} ` : 'SELECT * '; + let selectRaw = ''; + if (selectArray.length) { + switch (this._client) { + case 'maria': + case 'mysql': + selectRaw = selectArray.length ? `SELECT ${selectArray.join(', ')} ` : 'SELECT * '; + break; + case 'mssql': { + 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 - let fromRaw; + let fromRaw = ''; + if (!this._query.update.length) + fromRaw = 'FROM'; + switch (this._client) { case 'maria': 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; 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; default: break; @@ -183,8 +193,13 @@ export class AntaresConnector { const whereArray = this._query.where.reduce(this._reducer, []); 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 groupByRaw = groupByArray.length ? `GROUP BY ${groupByArray.join(', ')} ` : ''; + const orderByArray = this._query.orderBy.reduce(this._reducer, []); const orderByRaw = orderByArray.length ? `ORDER BY ${orderByArray.join(', ')} ` : ''; @@ -202,7 +217,7 @@ export class AntaresConnector { break; } - return `${selectRaw}${fromRaw}${whereRaw}${groupByRaw}${orderByRaw}${limitRaw}`; + return `${selectRaw}${updateRaw ? 'UPDATE' : ''}${fromRaw}${updateRaw}${whereRaw}${groupByRaw}${orderByRaw}${limitRaw}`; } /** diff --git a/src/main/models/Generic.js b/src/main/models/Generic.js index fe9389ed..418c1163 100644 --- a/src/main/models/Generic.js +++ b/src/main/models/Generic.js @@ -20,4 +20,13 @@ export default class { .limit(1000) .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(); + } } diff --git a/src/renderer/components/ModalSettings.vue b/src/renderer/components/ModalSettings.vue index 750417c3..1eb6346e 100644 --- a/src/renderer/components/ModalSettings.vue +++ b/src/renderer/components/ModalSettings.vue @@ -87,7 +87,7 @@
{{ $t('word.version') }}: {{ appVersion }}
- GitHub
+ GitHub
{{ $t('message.madeWithJS') }}