Skip to content

Commit

Permalink
feat(Firebird SQL): support to blob fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Nov 8, 2022
1 parent 2c8509f commit 0827a04
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/common/customizations/firebird.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const customizations: Customizations = {
schemaExport: false,
exportByChunks: false,
schemaImport: false,
tableSettings: false,
tableSettings: true,
tableOptions: false,
tableArray: false,
tableRealCount: false,
Expand Down
75 changes: 47 additions & 28 deletions src/main/libs/clients/FirebirdSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class FirebirdSQLClient extends AntaresCore {
return null;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getStructure (_schemas: Set<string>) {
interface ShowTableResult {
FORMAT: number;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 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);
// }
// }
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);
// }
}

destroyConnectionToCommit (tabUid: string) {
// const connection = this._connectionsToCommit.get(tabUid);
// if (connection) {
// connection.close();
// this._connectionsToCommit.delete(tabUid);
// }
}

getSQL () {
// LIMIT
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 7 additions & 5 deletions src/renderer/components/WorkspaceTabPropsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/scss/_table-keys.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

&.key-mul,
&.key-INDEX,
&.key-fk,
&.key-KEY {
color: limegreen;
}

&.key-fk {
color: chocolate;
}

&.key-FULLTEXT {
color: mediumvioletred;
}
Expand Down

0 comments on commit 0827a04

Please sign in to comment.