mongoDB - bigint support WIP

This commit is contained in:
SPRINX0\prochazka
2025-05-05 17:16:46 +02:00
parent ce7559087e
commit b9d4197b5c
5 changed files with 24 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ const driverBase = require('../frontend/driver');
const Analyser = require('./Analyser');
const { MongoClient, ObjectId, AbstractCursor } = require('mongodb');
const { EJSON } = require('bson');
const { serializeJsTypesForJsonStringify } = require('dbgate-tools');
const createBulkInsertStream = require('./createBulkInsertStream');
const {
convertToMongoCondition,
@@ -13,7 +14,9 @@ const {
} = require('../frontend/convertToMongoCondition');
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) {

View File

@@ -5,11 +5,17 @@ const { mongoSplitterOptions } = require('dbgate-query-splitter/lib/options');
const _pickBy = require('lodash/pickBy');
const _fromPairs = require('lodash/fromPairs');
function mongoReplacer(key, value) {
if (typeof value === 'bigint') {
return { $bigint: value.toString() };
}
return value;
}
function jsonStringifyWithObjectId(obj) {
return JSON.stringify(obj, undefined, 2).replace(
/\{\s*\"\$oid\"\s*\:\s*\"([0-9a-f]+)\"\s*\}/g,
(m, id) => `ObjectId("${id}")`
);
return JSON.stringify(obj, mongoReplacer, 2)
.replace(/\{\s*\"\$oid\"\s*\:\s*\"([0-9a-f]+)\"\s*\}/g, (m, id) => `ObjectId("${id}")`)
.replace(/\{\s*\"\$bigint\"\s*\:\s*\"([0-9]+)\"\s*\}/g, (m, num) => `${num}n`);
}
/** @type {import('dbgate-types').SqlDialect} */