mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 09:45:59 +00:00
export test finished
This commit is contained in:
@@ -25,12 +25,13 @@ function createImportStream() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createExportStream() {
|
function createExportStream() {
|
||||||
const writable = new Stream.Writable({ objectMode: true });
|
const writable = new stream.Writable({ objectMode: true });
|
||||||
writable.result = [];
|
writable.result = [];
|
||||||
writable._write = (object, encoding, done) => {
|
writable._write = (chunk, encoding, callback) => {
|
||||||
result.push(object);
|
writable.result.push(chunk);
|
||||||
done();
|
callback();
|
||||||
};
|
};
|
||||||
|
return writable;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('DB Import/export', () => {
|
describe('DB Import/export', () => {
|
||||||
@@ -125,18 +126,19 @@ describe('DB Import/export', () => {
|
|||||||
[6, 'Bosna, Hecegovina'],
|
[6, 'Bosna, Hecegovina'],
|
||||||
];
|
];
|
||||||
for (const row of data) {
|
for (const row of data) {
|
||||||
await runCommandOnDriver(conn, driver, 'insert into ~t1(~id, ~country) values (%v, %v)', ...row);
|
await runCommandOnDriver(conn, driver, dmp =>
|
||||||
|
dmp.put('insert into ~t1(~id, ~country) values (%v, %v)', ...row)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const reader = await tableReader({
|
const reader = await tableReader({
|
||||||
systemConnection: conn,
|
systemConnection: conn,
|
||||||
driver,
|
driver,
|
||||||
pureName: 't1',
|
pureName: 't1',
|
||||||
createIfNotExists: true,
|
|
||||||
});
|
});
|
||||||
const writer = createExportStream();
|
const writer = createExportStream();
|
||||||
await copyStream(reader, writer);
|
await copyStream(reader, writer);
|
||||||
|
|
||||||
expect(writer.result).toEqual(data);
|
expect(writer.result.filter(x => !x.__isStreamHeader).map(row => [row.id, row.country])).toEqual(data);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,12 +8,15 @@ const logger = getLogger('tableReader');
|
|||||||
* @param {object} options
|
* @param {object} options
|
||||||
* @param {connectionType} options.connection - connection object
|
* @param {connectionType} options.connection - connection object
|
||||||
* @param {object} options.systemConnection - system connection (result of driver.connect). If not provided, new connection will be created
|
* @param {object} options.systemConnection - system connection (result of driver.connect). If not provided, new connection will be created
|
||||||
|
* @param {object} options.driver - driver object. If not provided, it will be loaded from connection
|
||||||
* @param {string} options.pureName - table name
|
* @param {string} options.pureName - table name
|
||||||
* @param {string} options.schemaName - schema name
|
* @param {string} options.schemaName - schema name
|
||||||
* @returns {Promise<readerType>} - reader object
|
* @returns {Promise<readerType>} - reader object
|
||||||
*/
|
*/
|
||||||
async function tableReader({ connection, systemConnection, pureName, schemaName }) {
|
async function tableReader({ connection, systemConnection, pureName, schemaName, driver }) {
|
||||||
const driver = requireEngineDriver(connection);
|
if (!driver) {
|
||||||
|
driver = requireEngineDriver(connection);
|
||||||
|
}
|
||||||
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
||||||
logger.info(`Connected.`);
|
logger.info(`Connected.`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user