mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 17:16:01 +00:00
Refactor binary data handling in SQL dumper and update test for binary insertion
This commit is contained in:
@@ -228,7 +228,6 @@ describe('Query', () => {
|
|||||||
'Binary',
|
'Binary',
|
||||||
testWrapper(async (conn, driver, engine) => {
|
testWrapper(async (conn, driver, engine) => {
|
||||||
await runCommandOnDriver(conn, driver, dmp =>
|
await runCommandOnDriver(conn, driver, dmp =>
|
||||||
// bytea
|
|
||||||
dmp.createTable({
|
dmp.createTable({
|
||||||
pureName: 't1',
|
pureName: 't1',
|
||||||
columns: [
|
columns: [
|
||||||
@@ -240,13 +239,11 @@ describe('Query', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const structure = await driver.analyseFull(conn);
|
const structure = await driver.analyseFull(conn);
|
||||||
const table = structure.tables.find(x => x.pureName == 't1');
|
const table = structure.tables.find(x => x.pureName == 't1');
|
||||||
|
|
||||||
await runCommandOnDriver(conn, driver, dmp => dmp.put("INSERT INTO t1 (val) VALUES (%v)", {$binary: {base64: 'iVBORw0KWgo='}}));
|
await runCommandOnDriver(conn, driver, dmp => dmp.put("INSERT INTO ~t1 (~val) VALUES (%v)", {$binary: {base64: 'iVBORw0KWgo='}}));
|
||||||
|
const res2 = await runQueryOnDriver(conn, driver, dmp => dmp.put('SELECT ~val FROM ~t1'));
|
||||||
const res2 = await runQueryOnDriver(conn, driver, dmp => dmp.put('SELECT val FROM t1'));
|
|
||||||
|
|
||||||
const row = res2.rows[0];
|
const row = res2.rows[0];
|
||||||
const keys = Object.keys(row);
|
const keys = Object.keys(row);
|
||||||
|
|||||||
@@ -78,7 +78,9 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
else if (_isNumber(value)) this.putRaw(value.toString());
|
else if (_isNumber(value)) this.putRaw(value.toString());
|
||||||
else if (_isDate(value)) this.putStringValue(new Date(value).toISOString());
|
else if (_isDate(value)) this.putStringValue(new Date(value).toISOString());
|
||||||
else if (value?.type == 'Buffer' && _isArray(value?.data)) this.putByteArrayValue(value?.data);
|
else if (value?.type == 'Buffer' && _isArray(value?.data)) this.putByteArrayValue(value?.data);
|
||||||
else if (value?.$binary) this.putByteArrayValue(Buffer.from(value?.$binary.base64, 'base64'));
|
else if (value?.$binary?.base64) {
|
||||||
|
this.putByteArrayValue(Array.from(Buffer.from(value.$binary.base64, 'base64')));
|
||||||
|
}
|
||||||
else if (value?.$bigint) this.putRaw(value?.$bigint);
|
else if (value?.$bigint) this.putRaw(value?.$bigint);
|
||||||
else if (_isPlainObject(value) || _isArray(value)) this.putStringValue(JSON.stringify(value));
|
else if (_isPlainObject(value) || _isArray(value)) this.putStringValue(JSON.stringify(value));
|
||||||
else this.put('^null');
|
else this.put('^null');
|
||||||
|
|||||||
Reference in New Issue
Block a user