mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 00:45:58 +00:00
mongoDB - bigint support WIP
This commit is contained in:
@@ -255,7 +255,7 @@ async function handleDriverDataCore(msgid, callMethod, { logName }) {
|
|||||||
const driver = requireEngineDriver(storedConnection);
|
const driver = requireEngineDriver(storedConnection);
|
||||||
try {
|
try {
|
||||||
const result = await callMethod(driver);
|
const result = await callMethod(driver);
|
||||||
process.send({ msgtype: 'response', msgid, result });
|
process.send({ msgtype: 'response', msgid, result: serializeJsTypesForJsonStringify(result) });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(extractErrorLogData(err, { logName }), `Error when handling message ${logName}`);
|
logger.error(extractErrorLogData(err, { logName }), `Error when handling message ${logName}`);
|
||||||
process.send({ msgtype: 'response', msgid, errorMessage: extractErrorMessage(err, 'Error executing DB data') });
|
process.send({ msgtype: 'response', msgid, errorMessage: extractErrorMessage(err, 'Error executing DB data') });
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export function parseCellValue(value, editorTypes?: DataEditorTypesBehaviour) {
|
|||||||
|
|
||||||
if (editorTypes?.parseNumber) {
|
if (editorTypes?.parseNumber) {
|
||||||
if (/^-?[0-9]+(?:\.[0-9]+)?$/.test(value)) {
|
if (/^-?[0-9]+(?:\.[0-9]+)?$/.test(value)) {
|
||||||
return parseFloat(value);
|
return parseNumberSafe(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,6 +215,12 @@ export function stringifyCellValue(
|
|||||||
gridStyle: 'valueCellStyle',
|
gridStyle: 'valueCellStyle',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (typeof value === 'bigint') {
|
||||||
|
return {
|
||||||
|
value: value.toString(),
|
||||||
|
gridStyle: 'valueCellStyle',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (editorTypes?.parseDateAsDollar) {
|
if (editorTypes?.parseDateAsDollar) {
|
||||||
if (value?.$date) {
|
if (value?.$date) {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
{ useThousandsSeparator: getBoolSettingsValue('dataGrid.thousandsSeparator', false) },
|
{ useThousandsSeparator: getBoolSettingsValue('dataGrid.thousandsSeparator', false) },
|
||||||
jsonParsedValue
|
jsonParsedValue
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// $: console.log('CellValue', value, stringified);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if rowData == null}
|
{#if rowData == null}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const driverBase = require('../frontend/driver');
|
|||||||
const Analyser = require('./Analyser');
|
const Analyser = require('./Analyser');
|
||||||
const { MongoClient, ObjectId, AbstractCursor } = require('mongodb');
|
const { MongoClient, ObjectId, AbstractCursor } = require('mongodb');
|
||||||
const { EJSON } = require('bson');
|
const { EJSON } = require('bson');
|
||||||
|
const { serializeJsTypesForJsonStringify } = require('dbgate-tools');
|
||||||
const createBulkInsertStream = require('./createBulkInsertStream');
|
const createBulkInsertStream = require('./createBulkInsertStream');
|
||||||
const {
|
const {
|
||||||
convertToMongoCondition,
|
convertToMongoCondition,
|
||||||
@@ -13,7 +14,9 @@ const {
|
|||||||
} = require('../frontend/convertToMongoCondition');
|
} = require('../frontend/convertToMongoCondition');
|
||||||
|
|
||||||
function transformMongoData(row) {
|
function transformMongoData(row) {
|
||||||
return EJSON.serialize(row);
|
// TODO process LONG type
|
||||||
|
// console.log('ROW', row);
|
||||||
|
return EJSON.serialize(serializeJsTypesForJsonStringify(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readCursor(cursor, options) {
|
async function readCursor(cursor, options) {
|
||||||
|
|||||||
@@ -5,11 +5,17 @@ const { mongoSplitterOptions } = require('dbgate-query-splitter/lib/options');
|
|||||||
const _pickBy = require('lodash/pickBy');
|
const _pickBy = require('lodash/pickBy');
|
||||||
const _fromPairs = require('lodash/fromPairs');
|
const _fromPairs = require('lodash/fromPairs');
|
||||||
|
|
||||||
|
function mongoReplacer(key, value) {
|
||||||
|
if (typeof value === 'bigint') {
|
||||||
|
return { $bigint: value.toString() };
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
function jsonStringifyWithObjectId(obj) {
|
function jsonStringifyWithObjectId(obj) {
|
||||||
return JSON.stringify(obj, undefined, 2).replace(
|
return JSON.stringify(obj, mongoReplacer, 2)
|
||||||
/\{\s*\"\$oid\"\s*\:\s*\"([0-9a-f]+)\"\s*\}/g,
|
.replace(/\{\s*\"\$oid\"\s*\:\s*\"([0-9a-f]+)\"\s*\}/g, (m, id) => `ObjectId("${id}")`)
|
||||||
(m, id) => `ObjectId("${id}")`
|
.replace(/\{\s*\"\$bigint\"\s*\:\s*\"([0-9]+)\"\s*\}/g, (m, num) => `${num}n`);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {import('dbgate-types').SqlDialect} */
|
/** @type {import('dbgate-types').SqlDialect} */
|
||||||
|
|||||||
Reference in New Issue
Block a user