From 48ebf23bd1574408f429f2e1200ce878352007f6 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Sun, 30 Jan 2022 11:45:24 +0100 Subject: [PATCH] feat(MySQL): spatial fields support (#165) * feat: POINT field support * feat(MySQL): support to LINESTRING, POLYGON and GEOMETRY fields * refactor: removed links from map attribution * feat(MySQL): support to MULTIPOINT, MULTILINESTRING, MULTIPOLYGON and GEOMCOLLECTION fields * test: temporary fix on Windows tests --- package.json | 4 +- src/common/data-types/mysql.js | 18 +-- src/common/fieldTypes.js | 25 +++- src/common/libs/getArrayDepth.js | 10 ++ src/renderer/components/BaseMap.vue | 108 ++++++++++++++++++ .../components/WorkspaceTabQueryTable.vue | 4 +- .../components/WorkspaceTabQueryTableRow.vue | 60 +++++++++- src/renderer/index.js | 1 + src/renderer/scss/_data-types.scss | 9 ++ 9 files changed, 223 insertions(+), 16 deletions(-) create mode 100644 src/common/libs/getArrayDepth.js create mode 100644 src/renderer/components/BaseMap.vue diff --git a/package.json b/package.json index 66d8d4d2..9cdb975e 100644 --- a/package.json +++ b/package.json @@ -106,6 +106,7 @@ "dependencies": { "@electron/remote": "^2.0.1", "@mdi/font": "^6.1.95", + "@turf/helpers": "^6.5.0", "@vscode/vscode-languagedetection": "^1.0.21", "ace-builds": "^1.4.13", "better-sqlite3": "^7.4.4", @@ -113,7 +114,8 @@ "electron-store": "^8.0.1", "electron-updater": "^4.6.1", "electron-window-state": "^5.0.3", - "faker": "~5.5.3", + "faker": "^5.5.3", + "leaflet": "^1.7.1", "marked": "^4.0.0", "moment": "^2.29.1", "mysql2": "^2.3.2", diff --git a/src/common/data-types/mysql.js b/src/common/data-types/mysql.js index f1eeaf33..8e77f900 100644 --- a/src/common/data-types/mysql.js +++ b/src/common/data-types/mysql.js @@ -219,56 +219,56 @@ module.exports = [ types: [ { name: 'POINT', - length: true, + length: false, collation: false, unsigned: false, zerofill: false }, { name: 'LINESTRING', - length: true, + length: false, collation: false, unsigned: false, zerofill: false }, { name: 'POLYGON', - length: true, + length: false, collation: false, unsigned: false, zerofill: false }, { name: 'GEOMETRY', - length: true, + length: false, collation: false, unsigned: false, zerofill: false }, { name: 'MULTIPOINT', - length: true, + length: false, collation: false, unsigned: false, zerofill: false }, { name: 'MULTILINESTRING', - length: true, + length: false, collation: false, unsigned: false, zerofill: false }, { name: 'MULTIPOLYGON', - length: true, + length: false, collation: false, unsigned: false, zerofill: false }, { - name: 'GEOMETRYCOLLECTION', - length: true, + name: 'GEOMCOLLECTION', + length: false, collation: false, unsigned: false, zerofill: false diff --git a/src/common/fieldTypes.js b/src/common/fieldTypes.js index d3a8a1db..a7d3399f 100644 --- a/src/common/fieldTypes.js +++ b/src/common/fieldTypes.js @@ -8,7 +8,9 @@ export const TEXT = [ export const LONG_TEXT = [ 'TEXT', 'MEDIUMTEXT', - 'LONGTEXT' + 'LONGTEXT', + 'JSON', + 'VARBINARY' ]; export const ARRAY = [ @@ -82,3 +84,24 @@ export const BIT = [ 'BIT', 'BIT VARYING' ]; + +export const SPATIAL = [ + 'POINT', + 'LINESTRING', + 'POLYGON', + 'GEOMETRY', + 'MULTIPOINT', + 'MULTILINESTRING', + 'MULTIPOLYGON', + 'GEOMCOLLECTION', + 'GEOMETRYCOLLECTION' +]; + +// Used to check multi spatial fields only +export const IS_MULTI_SPATIAL = [ + 'MULTIPOINT', + 'MULTILINESTRING', + 'MULTIPOLYGON', + 'GEOMCOLLECTION', + 'GEOMETRYCOLLECTION' +]; diff --git a/src/common/libs/getArrayDepth.js b/src/common/libs/getArrayDepth.js new file mode 100644 index 00000000..04e62e77 --- /dev/null +++ b/src/common/libs/getArrayDepth.js @@ -0,0 +1,10 @@ +/** + * + * @param {any[]} array + * @returns {number} + */ +export function getArrayDepth (array) { + return Array.isArray(array) + ? 1 + Math.max(0, ...array.map(getArrayDepth)) + : 0; +} diff --git a/src/renderer/components/BaseMap.vue b/src/renderer/components/BaseMap.vue new file mode 100644 index 00000000..c1cbb836 --- /dev/null +++ b/src/renderer/components/BaseMap.vue @@ -0,0 +1,108 @@ + + + + diff --git a/src/renderer/components/WorkspaceTabQueryTable.vue b/src/renderer/components/WorkspaceTabQueryTable.vue index d41ebb44..fbd33279 100644 --- a/src/renderer/components/WorkspaceTabQueryTable.vue +++ b/src/renderer/components/WorkspaceTabQueryTable.vue @@ -412,7 +412,9 @@ export default { `${this.fields[0].table}.${this.selectedCell.field}`, `${this.fields[0].tableAlias}.${this.selectedCell.field}` ].includes(prop)); - const valueToCopy = row[cellName]; + let valueToCopy = row[cellName]; + if (typeof valueToCopy === 'object') + valueToCopy = JSON.stringify(valueToCopy); navigator.clipboard.writeText(valueToCopy); }, copyRow () { diff --git a/src/renderer/components/WorkspaceTabQueryTableRow.vue b/src/renderer/components/WorkspaceTabQueryTableRow.vue index f417322c..6fe51f13 100644 --- a/src/renderer/components/WorkspaceTabQueryTableRow.vue +++ b/src/renderer/components/WorkspaceTabQueryTableRow.vue @@ -123,6 +123,21 @@ + + + +