diff --git a/packages/tools/src/SqlDumper.ts b/packages/tools/src/SqlDumper.ts index 76883868..abc10807 100644 --- a/packages/tools/src/SqlDumper.ts +++ b/packages/tools/src/SqlDumper.ts @@ -22,6 +22,8 @@ import { import _isString from 'lodash/isString'; import _isNumber from 'lodash/isNumber'; import _isDate from 'lodash/isDate'; +import _isArray from 'lodash/isArray'; +import _isPlainObject from 'lodash/isPlainObject'; import uuidv1 from 'uuid/v1'; export class SqlDumper implements AlterProcessor { @@ -57,6 +59,9 @@ export class SqlDumper implements AlterProcessor { this.putRaw(this.escapeString(value)); this.putRaw("'"); } + putByteArrayValue(value) { + this.putRaw('NULL'); + } putValue(value) { if (value === null) this.putRaw('NULL'); else if (value === true) this.putRaw('1'); @@ -64,6 +69,8 @@ export class SqlDumper implements AlterProcessor { else if (_isString(value)) this.putStringValue(value); else if (_isNumber(value)) this.putRaw(value.toString()); else if (_isDate(value)) this.putStringValue(new Date(value).toISOString()); + else if (value?.type == 'Buffer' && _isArray(value?.data)) this.putByteArrayValue(value?.data); + else if (_isPlainObject(value) || _isArray(value)) this.putStringValue(JSON.stringify(value)); else this.putRaw('NULL'); } putCmd(format, ...args) { diff --git a/packages/tools/src/stringTools.ts b/packages/tools/src/stringTools.ts index d3a44c5a..80f7d858 100644 --- a/packages/tools/src/stringTools.ts +++ b/packages/tools/src/stringTools.ts @@ -1,5 +1,9 @@ +import _isString from 'lodash/isString'; +import _isArray from 'lodash/isArray'; +import _isPlainObject from 'lodash/isPlainObject'; + export function arrayToHexString(byteArray) { - return byteArray.reduce((output, elem) => output + ('0' + elem.toString(16)).slice(-2), ''); + return byteArray.reduce((output, elem) => output + ('0' + elem.toString(16)).slice(-2), '').toUpperCase(); } export function hexStringToArray(inputString) { @@ -10,3 +14,33 @@ export function hexStringToArray(inputString) { } return res; } + +export function parseCellValue(value) { + if (!_isString(value)) return value; + + if (value == '(NULL)') return null; + + const mHex = value.match(/^0x([0-9a-fA-F][0-9a-fA-F])+$/); + if (mHex) { + return { + type: 'Buffer', + data: hexStringToArray(value.substring(2)), + }; + } + + const mOid = value.match(/^ObjectId\("([0-9a-f]{24})"\)$/); + if (mOid) { + return { $oid: mOid[1] }; + } + + return value; +} + +export function stringifyCellValue(value) { + if (value === null) return '(NULL)'; + if (value === undefined) return '(NoField)'; + if (value?.type == 'Buffer' && _isArray(value.data)) return '0x' + arrayToHexString(value.data); + if (value?.$oid) return `ObjectId("${value?.$oid}")`; + if (_isPlainObject(value) || _isArray(value)) return JSON.stringify(value); + return value; +} diff --git a/packages/web/src/celldata/PictureCellView.svelte b/packages/web/src/celldata/PictureCellView.svelte new file mode 100644 index 00000000..a3d824e1 --- /dev/null +++ b/packages/web/src/celldata/PictureCellView.svelte @@ -0,0 +1,35 @@ + + +{#if picture} +
+ +
+{:else} + +{/if} + + diff --git a/packages/web/src/datagrid/DataGridCell.svelte b/packages/web/src/datagrid/DataGridCell.svelte index 7ebd565f..1eb4b5e2 100644 --- a/packages/web/src/datagrid/DataGridCell.svelte +++ b/packages/web/src/datagrid/DataGridCell.svelte @@ -120,7 +120,7 @@ {/if} {:else if value?.type == 'Buffer' && _.isArray(value.data)} {#if value.data.length <= 16} - {arrayToHexString(value.data)} + {'0x' + arrayToHexString(value.data)} {:else} ({value.data.length} bytes) {/if} diff --git a/packages/web/src/datagrid/DataGridCore.svelte b/packages/web/src/datagrid/DataGridCore.svelte index e3f6175f..d2aa6e83 100644 --- a/packages/web/src/datagrid/DataGridCore.svelte +++ b/packages/web/src/datagrid/DataGridCore.svelte @@ -235,7 +235,7 @@