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 @@