mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 16:43:59 +00:00
simplified blob loading for firebird
This commit is contained in:
@@ -4,7 +4,7 @@ const stream = require('stream');
|
|||||||
const driverBase = require('../frontend/driver');
|
const driverBase = require('../frontend/driver');
|
||||||
const Analyser = require('./Analyser');
|
const Analyser = require('./Analyser');
|
||||||
const Firebird = require('node-firebird');
|
const Firebird = require('node-firebird');
|
||||||
const { normalizeRow, createFirebirdInsertStream } = require('./helpers');
|
const { createFirebirdInsertStream } = require('./helpers');
|
||||||
const { getLogger, extractErrorLogData, createBulkInsertStreamBase } = require('dbgate-tools');
|
const { getLogger, extractErrorLogData, createBulkInsertStreamBase } = require('dbgate-tools');
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ const driver = {
|
|||||||
database: databaseFile,
|
database: databaseFile,
|
||||||
user,
|
user,
|
||||||
password,
|
password,
|
||||||
|
blobAsText: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**@type {Firebird.Database} */
|
/**@type {Firebird.Database} */
|
||||||
@@ -63,7 +64,7 @@ const driver = {
|
|||||||
const columns = res?.[0] ? Object.keys(res[0]).map(i => ({ columnName: i })) : [];
|
const columns = res?.[0] ? Object.keys(res[0]).map(i => ({ columnName: i })) : [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
rows: res ? await Promise.all(res.map(normalizeRow)) : [],
|
rows: res || [],
|
||||||
columns,
|
columns,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -91,43 +91,6 @@ function getFormattedDefaultValue(defaultValue) {
|
|||||||
|
|
||||||
return defaultValue.replace(/^default\s*/i, '');
|
return defaultValue.replace(/^default\s*/i, '');
|
||||||
}
|
}
|
||||||
function blobStreamToString(stream, encoding = 'utf8') {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const chunks = [];
|
|
||||||
stream.on('data', chunk => {
|
|
||||||
chunks.push(chunk);
|
|
||||||
});
|
|
||||||
stream.on('end', () => {
|
|
||||||
resolve(Buffer.concat(chunks).toString(encoding));
|
|
||||||
});
|
|
||||||
stream.on('error', err => {
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function normalizeRow(row) {
|
|
||||||
const entries = await Promise.all(
|
|
||||||
Object.entries(row).map(async ([key, value]) => {
|
|
||||||
if (value === null || value === undefined) return [key, null];
|
|
||||||
if (typeof value === 'function') {
|
|
||||||
const result = await new Promise((resolve, reject) => {
|
|
||||||
value(async (_err, _name, eventEmitter) => {
|
|
||||||
try {
|
|
||||||
const stringValue = await blobStreamToString(eventEmitter, 'utf8');
|
|
||||||
resolve(stringValue);
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return [key, result];
|
|
||||||
}
|
|
||||||
return [key, value];
|
|
||||||
})
|
|
||||||
);
|
|
||||||
return Object.fromEntries(entries);
|
|
||||||
}
|
|
||||||
|
|
||||||
function transformRow(row) {
|
function transformRow(row) {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
|
|||||||
Reference in New Issue
Block a user