From 0827a04d61af75b4366394e5f0289df461d02c98 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Tue, 8 Nov 2022 15:53:21 +0100 Subject: [PATCH] feat(Firebird SQL): support to blob fields --- src/common/customizations/firebird.ts | 2 +- src/main/libs/clients/FirebirdSQLClient.ts | 71 ++++++++++++------- .../components/WorkspaceTabPropsTable.vue | 12 ++-- src/renderer/scss/_table-keys.scss | 5 +- 4 files changed, 57 insertions(+), 33 deletions(-) diff --git a/src/common/customizations/firebird.ts b/src/common/customizations/firebird.ts index 293a3ec5..e81c7abf 100644 --- a/src/common/customizations/firebird.ts +++ b/src/common/customizations/firebird.ts @@ -44,7 +44,7 @@ export const customizations: Customizations = { schemaExport: false, exportByChunks: false, schemaImport: false, - tableSettings: false, + tableSettings: true, tableOptions: false, tableArray: false, tableRealCount: false, diff --git a/src/main/libs/clients/FirebirdSQLClient.ts b/src/main/libs/clients/FirebirdSQLClient.ts index 6f4bc4eb..54895c52 100644 --- a/src/main/libs/clients/FirebirdSQLClient.ts +++ b/src/main/libs/clients/FirebirdSQLClient.ts @@ -77,6 +77,7 @@ export class FirebirdSQLClient extends AntaresCore { return null; } + // eslint-disable-next-line @typescript-eslint/no-unused-vars async getStructure (_schemas: Set) { interface ShowTableResult { FORMAT: number; @@ -466,17 +467,17 @@ export class FirebirdSQLClient extends AntaresCore { } async duplicateTable (params: { schema: string; table: string }) { // TODO: retrive table informations and create a copy - const sql = `CREATE TABLE '${params.table}_copy' AS SELECT * FROM '${params.table}'`; + const sql = `CREATE TABLE "${params.table}_copy" AS SELECT * FROM "${params.table}"`; return await this.raw(sql); } async truncateTable (params: { schema: string; table: string }) { - const sql = `DELETE FROM '${params.table}'`; + const sql = `DELETE FROM "${params.table}"`; return await this.raw(sql); } async dropTable (params: { schema: string; table: string }) { - const sql = `DROP TABLE '${params.table}'`; + const sql = `DROP TABLE "${params.table}"`; return await this.raw(sql); } @@ -586,29 +587,29 @@ export class FirebirdSQLClient extends AntaresCore { return null; } - // async commitTab (tabUid: string) { - // const connection = this._connectionsToCommit.get(tabUid); - // if (connection) { - // connection.prepare('COMMIT').run(); - // return this.destroyConnectionToCommit(tabUid); - // } - // } + async commitTab (tabUid: string) { + // const connection = this._connectionsToCommit.get(tabUid); + // if (connection) { + // connection.prepare('COMMIT').run(); + // return this.destroyConnectionToCommit(tabUid); + // } + } - // async rollbackTab (tabUid: string) { - // const connection = this._connectionsToCommit.get(tabUid); - // if (connection) { - // connection.prepare('ROLLBACK').run(); - // return this.destroyConnectionToCommit(tabUid); - // } - // } + async rollbackTab (tabUid: string) { + // const connection = this._connectionsToCommit.get(tabUid); + // if (connection) { + // connection.prepare('ROLLBACK').run(); + // return this.destroyConnectionToCommit(tabUid); + // } + } - // destroyConnectionToCommit (tabUid: string) { - // const connection = this._connectionsToCommit.get(tabUid); - // if (connection) { - // connection.close(); - // this._connectionsToCommit.delete(tabUid); - // } - // } + destroyConnectionToCommit (tabUid: string) { + // const connection = this._connectionsToCommit.get(tabUid); + // if (connection) { + // connection.close(); + // this._connectionsToCommit.delete(tabUid); + // } + } getSQL () { // LIMIT @@ -755,8 +756,26 @@ export class FirebirdSQLClient extends AntaresCore { for (const key in row) { if (Buffer.isBuffer(row[key])) row[key] = row[key].toString('binary'); - else if (typeof row[key] === 'function') - row[key] = row[key].toString('binary'); + else if (typeof row[key] === 'function') { + const result = await new Promise((resolve, reject) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + row[key]((err: any, _name: string, event: any) => { + if (err) + return reject(err); + + const buffArr: Buffer[] = []; + event.on('data', (chunk: Buffer) => { + buffArr.push(chunk); + }); + + event.on('end', () => { + resolve(Buffer.concat(buffArr)); + }); + }); + }); + + row[key] = result; + } } remappedResponse.push(row); diff --git a/src/renderer/components/WorkspaceTabPropsTable.vue b/src/renderer/components/WorkspaceTabPropsTable.vue index f97955ae..7db19f74 100644 --- a/src/renderer/components/WorkspaceTabPropsTable.vue +++ b/src/renderer/components/WorkspaceTabPropsTable.vue @@ -323,11 +323,13 @@ const getFieldsData = async () => { const { status, response } = await Tables.getTableIndexes(params); if (status === 'success') { - const indexesObj = response.reduce((acc: {[key: string]: TableIndex[]}, curr: TableIndex) => { - acc[curr.name] = acc[curr.name] || []; - acc[curr.name].push(curr); - return acc; - }, {}); + const indexesObj = response + .filter((index: TableIndex) => index.type !== 'FOREIGN KEY') + .reduce((acc: {[key: string]: TableIndex[]}, curr: TableIndex) => { + acc[curr.name] = acc[curr.name] || []; + acc[curr.name].push(curr); + return acc; + }, {}); originalIndexes.value = Object.keys(indexesObj).map(index => { return { diff --git a/src/renderer/scss/_table-keys.scss b/src/renderer/scss/_table-keys.scss index a57546b8..0c28866a 100644 --- a/src/renderer/scss/_table-keys.scss +++ b/src/renderer/scss/_table-keys.scss @@ -17,11 +17,14 @@ &.key-mul, &.key-INDEX, - &.key-fk, &.key-KEY { color: limegreen; } + &.key-fk { + color: chocolate; + } + &.key-FULLTEXT { color: mediumvioletred; }