diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index ef4b6a43..c8a50db0 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,6 +1,6 @@ # These are supported funding model platforms -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +github: [fabio286] patreon: fabio286 open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username diff --git a/src/main/index.js b/src/main/index.js index 6b760f3e..876e4f8d 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -3,7 +3,6 @@ import { app, BrowserWindow, nativeImage } from 'electron'; import * as path from 'path'; import { format as formatUrl } from 'url'; - import ipcHandlers from './ipc-handlers'; const isDevelopment = process.env.NODE_ENV !== 'production'; diff --git a/src/main/ipc-handlers/tables.js b/src/main/ipc-handlers/tables.js index 6e9a7361..6d6d7921 100644 --- a/src/main/ipc-handlers/tables.js +++ b/src/main/ipc-handlers/tables.js @@ -64,4 +64,14 @@ export default (connections) => { return { status: 'error', response: err.toString() }; } }); + + ipcMain.handle('get-foreign-list', async (event, params) => { + try { + const results = await Tables.getForeignList(connections[params.uid], params); + return { status: 'success', response: results }; + } + catch (err) { + return { status: 'error', response: err.toString() }; + } + }); }; diff --git a/src/main/models/InformationSchema.js b/src/main/models/InformationSchema.js index 2729611f..af25b345 100644 --- a/src/main/models/InformationSchema.js +++ b/src/main/models/InformationSchema.js @@ -40,8 +40,6 @@ export default class { } static async getKeyUsage (connection, schema, table) { - // SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA='fep-gprs' AND TABLE_NAME='struttura_macchine' AND REFERENCED_TABLE_NAME IS NOT NULL; - const { rows } = await connection .select('*') .schema('information_schema') diff --git a/src/main/models/Tables.js b/src/main/models/Tables.js index 42bb8ae1..046b2de2 100644 --- a/src/main/models/Tables.js +++ b/src/main/models/Tables.js @@ -54,12 +54,13 @@ export default class { static async insertTableRows (connection, params) { const insertObj = {}; - console.log(params); for (const key in params.row) { const type = params.fields[key]; let escapedParam; - if (NUMBER.includes(type)) + if (params.row[key] === null) + escapedParam = 'NULL'; + else if (NUMBER.includes(type)) escapedParam = params.row[key]; else if ([...TEXT, ...LONG_TEXT].includes(type)) escapedParam = `"${sqlEscaper(params.row[key])}"`; @@ -85,4 +86,17 @@ export default class { .run(); } } + + static async getForeignList (connection, params) { + const query = connection + .select(`${params.column} AS foreignColumn`) + .schema(params.schema) + .from(params.table) + .orderBy('foreignColumn ASC'); + + if (params.description) + query.select(`LEFT(${params.description}, 20) AS foreignDescription`); + + return query.run(); + } } diff --git a/src/renderer/components/ForeignKeySelect.vue b/src/renderer/components/ForeignKeySelect.vue new file mode 100644 index 00000000..f13e3528 --- /dev/null +++ b/src/renderer/components/ForeignKeySelect.vue @@ -0,0 +1,89 @@ + + + diff --git a/src/renderer/components/ModalNewTableRow.vue b/src/renderer/components/ModalNewTableRow.vue index 2fb9f17f..fe9450a6 100644 --- a/src/renderer/components/ModalNewTableRow.vue +++ b/src/renderer/components/ModalNewTableRow.vue @@ -23,8 +23,15 @@
+ key.column); + }, + fields () { + return this.getWorkspaceTab(this.tabUid) ? this.getWorkspaceTab(this.tabUid).fields : []; + }, + keyUsage () { + return this.getWorkspaceTab(this.tabUid) ? this.getWorkspaceTab(this.tabUid).keyUsage : []; } }, watch: { @@ -194,7 +216,7 @@ export default { try { const { status, response } = await Tables.insertTableRows({ - uid: this.connection.uid, + uid: this.selectedWorkspace, schema: this.workspace.breadcrumbs.schema, table: this.workspace.breadcrumbs.table, row: rowToInsert, @@ -271,6 +293,10 @@ export default { if (!files.length) return; this.localRow[field] = files[0].path; + }, + + getKeyUsage (keyName) { + return this.keyUsage.find(key => key.column === keyName); } } }; diff --git a/src/renderer/components/WorkspaceQueryTableRow.vue b/src/renderer/components/WorkspaceQueryTableRow.vue index fece3791..1035d75d 100644 --- a/src/renderer/components/WorkspaceQueryTableRow.vue +++ b/src/renderer/components/WorkspaceQueryTableRow.vue @@ -16,6 +16,13 @@ :class="`${isNull(col)} type-${fieldType(cKey)}`" @dblclick="editON($event, col, cKey)" >{{ col | typeFormat(fieldType(cKey), fieldPrecision(cKey)) | cutText }} +