mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
/*
|
|
* CloudBeaver - Cloud Database Manager
|
|
* Copyright (C) 2020-2021 DBeaver Corp and others
|
|
*
|
|
* Licensed under the Apache License, Version 2.0.
|
|
* you may not use this file except in compliance with the License.
|
|
*/
|
|
|
|
import { ResultDataFormat } from '@cloudbeaver/core-sdk';
|
|
|
|
import { DatabaseDataAction } from '../../DatabaseDataAction';
|
|
import type { IDatabaseResultSet } from '../../IDatabaseResultSet';
|
|
import { databaseDataAction } from '../DatabaseDataActionDecorator';
|
|
import type { IDatabaseDataFormatAction } from '../IDatabaseDataFormatAction';
|
|
import type { IResultSetElementKey } from './IResultSetElementKey';
|
|
import { isResultSetContentValue } from './isResultSetContentValue';
|
|
import { ResultSetDataAction } from './ResultSetDataAction';
|
|
|
|
@databaseDataAction()
|
|
export class ResultSetFormatAction extends DatabaseDataAction<any, IDatabaseResultSet>
|
|
implements IDatabaseDataFormatAction<IResultSetElementKey, IDatabaseResultSet> {
|
|
static dataFormat = ResultDataFormat.Resultset;
|
|
|
|
isReadOnly(key: IResultSetElementKey): boolean {
|
|
let columnReadonly = false;
|
|
let cellReadonly = false;
|
|
|
|
const data = this.getAction(ResultSetDataAction);
|
|
|
|
if (key.column !== undefined) {
|
|
columnReadonly = data.getColumn(key.column)?.readOnly || false;
|
|
}
|
|
|
|
const value = data.getCellValue(key);
|
|
|
|
if (isResultSetContentValue(value)) {
|
|
cellReadonly = (
|
|
value.binary !== undefined
|
|
|| value.contentLength !== value.text?.length
|
|
);
|
|
} else if (value !== null && typeof value === 'object') {
|
|
cellReadonly = true;
|
|
}
|
|
|
|
return columnReadonly || cellReadonly;
|
|
}
|
|
|
|
isNull(value: any): boolean {
|
|
return this.get(value) === null;
|
|
}
|
|
|
|
get(value: any): any {
|
|
if (value !== null && typeof value === 'object') {
|
|
if ('text' in value) {
|
|
return value.text;
|
|
} else if ('value' in value) {
|
|
return value.value;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
getText(value: any): string {
|
|
if (value !== null && typeof value === 'object') {
|
|
return JSON.stringify(value);
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
toString(value: any): string {
|
|
value = this.getText(this.get(value));
|
|
|
|
if (typeof value === 'string' && value.length > 1000) {
|
|
return value.split('').map(v => (v.charCodeAt(0) < 32 ? ' ' : v)).join('');
|
|
}
|
|
|
|
if (value === null) {
|
|
return '[null]';
|
|
}
|
|
|
|
return String(value);
|
|
}
|
|
}
|