Skip to content

Commit

Permalink
feat(PostgreSQL): edit array and text search fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Mar 17, 2021
1 parent 9645702 commit fc65114
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
11 changes: 10 additions & 1 deletion src/common/fieldTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ export const TEXT = [
export const LONG_TEXT = [
'TEXT',
'MEDIUMTEXT',
'LONGTEXT',
'LONGTEXT'
];

export const ARRAY = [
'ARRAY',
'ANYARRAY'
];

export const TEXT_SEARCH = [
'TSVECTOR',
'TSQUERY'
];

export const NUMBER = [
'INT',
'TINYINT',
Expand Down Expand Up @@ -49,6 +57,7 @@ export const TIME = [
export const DATETIME = [
'DATETIME',
'TIMESTAMP',
'TIMESTAMP WITHOUT TIME ZONE',
'TIMESTAMP WITH TIME ZONE'
];

Expand Down
6 changes: 5 additions & 1 deletion src/main/ipc-handlers/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ipcMain } from 'electron';
import faker from 'faker';
import moment from 'moment';
import { sqlEscaper } from 'common/libs/sqlEscaper';
import { TEXT, LONG_TEXT, NUMBER, FLOAT, BLOB, BIT, DATE, DATETIME } from 'common/fieldTypes';
import { TEXT, LONG_TEXT, ARRAY, TEXT_SEARCH, NUMBER, FLOAT, BLOB, BIT, DATE, DATETIME } from 'common/fieldTypes';
import fs from 'fs';

export default (connections) => {
Expand Down Expand Up @@ -68,6 +68,10 @@ export default (connections) => {
escapedParam = params.content;
else if ([...TEXT, ...LONG_TEXT].includes(params.type))
escapedParam = `"${sqlEscaper(params.content)}"`;
else if (ARRAY.includes(params.type))
escapedParam = `'${params.content}'`;
else if (TEXT_SEARCH.includes(params.type))
escapedParam = `'${params.content.replaceAll('\'', '\'\'')}'`;
else if (BLOB.includes(params.type)) {
if (params.content) {
const fileBlob = fs.readFileSync(params.content);
Expand Down
11 changes: 7 additions & 4 deletions src/renderer/components/WorkspaceExploreBarSchema.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</ul>
</div>

<div v-if="filteredTriggers.length" class="database-misc">
<div v-if="filteredTriggers.length && customizations.triggers" class="database-misc">
<details class="accordion">
<summary class="accordion-header misc-name" :class="{'text-bold': breadcrumbs.schema === database.name && breadcrumbs.trigger}">
<i class="misc-icon mdi mdi-18px mdi-folder-cog mr-1" />
Expand Down Expand Up @@ -65,7 +65,7 @@
</details>
</div>

<div v-if="filteredProcedures.length" class="database-misc">
<div v-if="filteredProcedures.length && customizations.routines" class="database-misc">
<details class="accordion">
<summary class="accordion-header misc-name" :class="{'text-bold': breadcrumbs.schema === database.name && breadcrumbs.procedure}">
<i class="misc-icon mdi mdi-18px mdi-folder-sync mr-1" />
Expand Down Expand Up @@ -93,7 +93,7 @@
</details>
</div>

<div v-if="filteredFunctions.length" class="database-misc">
<div v-if="filteredFunctions.length && customizations.functions" class="database-misc">
<details class="accordion">
<summary class="accordion-header misc-name" :class="{'text-bold': breadcrumbs.schema === database.name && breadcrumbs.function}">
<i class="misc-icon mdi mdi-18px mdi-folder-move mr-1" />
Expand Down Expand Up @@ -121,7 +121,7 @@
</details>
</div>

<div v-if="filteredSchedulers.length" class="database-misc">
<div v-if="filteredSchedulers.length && customizations.schedulers" class="database-misc">
<details class="accordion">
<summary class="accordion-header misc-name" :class="{'text-bold': breadcrumbs.schema === database.name && breadcrumbs.scheduler}">
<i class="misc-icon mdi mdi-18px mdi-folder-clock mr-1" />
Expand Down Expand Up @@ -194,6 +194,9 @@ export default {
breadcrumbs () {
return this.getWorkspace(this.connection.uid).breadcrumbs;
},
customizations () {
return this.getWorkspace(this.connection.uid).customizations;
},
loadedSchemas () {
return this.getLoadedSchemas(this.connection.uid);
},
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/components/WorkspaceQueryTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ import { mimeFromHex } from 'common/libs/mimeFromHex';
import { formatBytes } from 'common/libs/formatBytes';
import { bufferToBase64 } from 'common/libs/bufferToBase64';
import hexToBinary from 'common/libs/hexToBinary';
import { TEXT, LONG_TEXT, NUMBER, FLOAT, DATE, TIME, DATETIME, BLOB, BIT } from 'common/fieldTypes';
import { TEXT, LONG_TEXT, ARRAY, TEXT_SEARCH, NUMBER, FLOAT, DATE, TIME, DATETIME, BLOB, BIT } from 'common/fieldTypes';
import { VueMaskDirective } from 'v-mask';
import ConfirmModal from '@/components/BaseConfirmModal';
import TextEditor from '@/components/BaseTextEditor';
Expand Down Expand Up @@ -225,6 +225,12 @@ export default {
return hexToBinary(hex);
}
if (ARRAY.includes(type)) {
if (Array.isArray(val))
return JSON.stringify(val).replaceAll('[', '{').replaceAll(']', '}');
return val;
}
return val;
}
},
Expand Down Expand Up @@ -350,7 +356,7 @@ export default {
this.editingField = field;
this.editingLength = this.fields[field].length;
if (LONG_TEXT.includes(type)) {
if ([...LONG_TEXT, ...ARRAY, ...TEXT_SEARCH].includes(type)) {
this.isTextareaEditor = true;
this.editingContent = this.$options.filters.typeFormat(content, type);
return;
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/i18n/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ module.exports = {
paste: 'Paste',
tools: 'Tools',
variables: 'Variables',
processes: 'Processes'
processes: 'Processes',
database: 'Database'
},
message: {
appWelcome: 'Welcome to Antares SQL Client!',
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/scss/_data-types.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"time_with_time_zone": $date-color,
"year": $date-color,
"timestamp": $date-color,
"timestamp_without_time_zone": $date-color,
"timestamp_with_time_zone": $date-color,
"bit": $bit-color,
"bit_varying": $bit-color,
Expand All @@ -72,6 +73,8 @@
"interval": $array-color,
"array": $array-color,
"anyarray": $array-color,
"tsvector": $array-color,
"tsquery": $array-color,
"pg_node_tree": $array-color,
"unknown": $unknown-color,
)
Expand Down

0 comments on commit fc65114

Please sign in to comment.