mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 18:56:00 +00:00
bigint support #1087
This commit is contained in:
@@ -4,6 +4,7 @@ import _isDate from 'lodash/isDate';
|
||||
import _isNumber from 'lodash/isNumber';
|
||||
import _isPlainObject from 'lodash/isPlainObject';
|
||||
import _pad from 'lodash/pad';
|
||||
import _cloneDeepWith from 'lodash/cloneDeepWith';
|
||||
import { DataEditorTypesBehaviour } from 'dbgate-types';
|
||||
|
||||
export type EditorDataType =
|
||||
@@ -208,6 +209,12 @@ export function stringifyCellValue(
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value?.$bigint) {
|
||||
return {
|
||||
value: value.$bigint,
|
||||
gridStyle: 'valueCellStyle',
|
||||
};
|
||||
}
|
||||
|
||||
if (editorTypes?.parseDateAsDollar) {
|
||||
if (value?.$date) {
|
||||
@@ -343,6 +350,9 @@ export function shouldOpenMultilineDialog(value) {
|
||||
if (value?.$date) {
|
||||
return false;
|
||||
}
|
||||
if (value?.$bigint) {
|
||||
return false;
|
||||
}
|
||||
if (_isPlainObject(value) || _isArray(value)) {
|
||||
return true;
|
||||
}
|
||||
@@ -573,3 +583,44 @@ export function jsonLinesParse(jsonLines: string): any[] {
|
||||
})
|
||||
.filter(x => x);
|
||||
}
|
||||
|
||||
export function serializeJsTypesForJsonStringify(obj) {
|
||||
return _cloneDeepWith(obj, value => {
|
||||
if (typeof value === 'bigint') {
|
||||
return { $bigint: value.toString() };
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function deserializeJsTypesFromJsonParse(obj) {
|
||||
return _cloneDeepWith(obj, value => {
|
||||
if (value?.$bigint) {
|
||||
return BigInt(value.$bigint);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function serializeJsTypesReplacer(key, value) {
|
||||
if (typeof value === 'bigint') {
|
||||
return { $bigint: value.toString() };
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function deserializeJsTypesReviver(key, value) {
|
||||
if (value?.$bigint) {
|
||||
return BigInt(value.$bigint);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function parseNumberSafe(value) {
|
||||
if (/^-?[0-9]+$/.test(value)) {
|
||||
const parsed = parseInt(value);
|
||||
if (Number.isSafeInteger(parsed)) {
|
||||
return parsed;
|
||||
}
|
||||
return BigInt(value);
|
||||
}
|
||||
return parseFloat(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user