mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 13:46:00 +00:00
fix: process blob values, update firebird dialect
This commit is contained in:
@@ -89,6 +89,43 @@ function getFormattedDefaultValue(defaultValue) {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getDataTypeString,
|
||||
@@ -96,4 +133,6 @@ module.exports = {
|
||||
getTriggerTiming,
|
||||
getFormattedDefaultValue,
|
||||
getTriggerCreateSql,
|
||||
blobStreamToString,
|
||||
normalizeRow,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user