mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 18:34:01 +00:00
db import test + fix for postgres
This commit is contained in:
43
integration-tests/__tests__/db-import.spec.js
Normal file
43
integration-tests/__tests__/db-import.spec.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
const engines = require('../engines');
|
||||||
|
const stream = require('stream');
|
||||||
|
const { testWrapper } = require('../tools');
|
||||||
|
const tableWriter = require('dbgate-api/src/shell/tableWriter');
|
||||||
|
const copyStream = require('dbgate-api/src/shell/copyStream');
|
||||||
|
const fakeObjectReader = require('dbgate-api/src/shell/fakeObjectReader');
|
||||||
|
|
||||||
|
function createImportStream() {
|
||||||
|
const pass = new stream.PassThrough({
|
||||||
|
objectMode: true,
|
||||||
|
});
|
||||||
|
pass.write({ columns: [{ columnName: 'id' }, { columnName: 'country' }], __isStreamHeader: true });
|
||||||
|
pass.write({ id: 1, country: 'Czechia' });
|
||||||
|
pass.write({ id: 2, country: 'Austria' });
|
||||||
|
pass.write({ country: 'Germany', id: 3 });
|
||||||
|
pass.write({ country: 'Romania', id: 4 });
|
||||||
|
pass.write({ country: 'Great Britain', id: 5 });
|
||||||
|
pass.write({ country: 'Bosna, Hecegovina', id: 6 });
|
||||||
|
pass.end();
|
||||||
|
|
||||||
|
return pass;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('DB Import', () => {
|
||||||
|
test.each(engines.map(engine => [engine.label, engine]))(
|
||||||
|
'Import one table - %s',
|
||||||
|
testWrapper(async (conn, driver, engine) => {
|
||||||
|
// const reader = await fakeObjectReader({ delay: 10 });
|
||||||
|
// const reader = await fakeObjectReader();
|
||||||
|
const reader = createImportStream();
|
||||||
|
const writer = await tableWriter({
|
||||||
|
systemConnection: conn,
|
||||||
|
driver,
|
||||||
|
pureName: 't1',
|
||||||
|
createIfNotExists: true,
|
||||||
|
});
|
||||||
|
await copyStream(reader, writer);
|
||||||
|
|
||||||
|
const res = await driver.query(conn, `select count(*) as cnt from t1`);
|
||||||
|
expect(res.rows[0].cnt.toString()).toEqual('6');
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -116,11 +116,11 @@ const engines = [
|
|||||||
|
|
||||||
const filterLocal = [
|
const filterLocal = [
|
||||||
// filter local testing
|
// filter local testing
|
||||||
'-MySQL',
|
'MySQL',
|
||||||
'PostgreSQL',
|
'PostgreSQL',
|
||||||
'-SQL Server',
|
'SQL Server',
|
||||||
'-SQLite',
|
'SQLite',
|
||||||
'-CockroachDB',
|
'CockroachDB',
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = process.env.CITEST
|
module.exports = process.env.CITEST
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ async function fakeObjectReader({ delay = 0 } = {}) {
|
|||||||
objectMode: true,
|
objectMode: true,
|
||||||
});
|
});
|
||||||
function doWrite() {
|
function doWrite() {
|
||||||
pass.write({ columns: [{ columnName: 'id' }, { columnName: 'country' }] });
|
pass.write({ columns: [{ columnName: 'id' }, { columnName: 'country' }], __isStreamHeader: true });
|
||||||
pass.write({ id: 1, country: 'Czechia' });
|
pass.write({ id: 1, country: 'Czechia' });
|
||||||
pass.write({ id: 2, country: 'Austria' });
|
pass.write({ id: 2, country: 'Austria' });
|
||||||
pass.write({ country: 'Germany', id: 3 });
|
pass.write({ country: 'Germany', id: 3 });
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
const { fullNameToString } = require('dbgate-tools');
|
const { fullNameToString } = require('dbgate-tools');
|
||||||
const requireEngineDriver = require('../utility/requireEngineDriver');
|
const requireEngineDriver = require('../utility/requireEngineDriver');
|
||||||
const { decryptConnection } = require('../utility/crypting');
|
|
||||||
const connectUtility = require('../utility/connectUtility');
|
const connectUtility = require('../utility/connectUtility');
|
||||||
|
|
||||||
async function tableWriter({ connection, schemaName, pureName, ...options }) {
|
async function tableWriter({ connection, schemaName, pureName, driver, systemConnection, ...options }) {
|
||||||
console.log(`Writing table ${fullNameToString({ schemaName, pureName })}`);
|
console.log(`Writing table ${fullNameToString({ schemaName, pureName })}`);
|
||||||
|
|
||||||
const driver = requireEngineDriver(connection);
|
if (!driver) {
|
||||||
const pool = await connectUtility(driver, connection);
|
driver = requireEngineDriver(connection);
|
||||||
|
}
|
||||||
|
const pool = systemConnection || (await connectUtility(driver, connection));
|
||||||
|
|
||||||
console.log(`Connected.`);
|
console.log(`Connected.`);
|
||||||
return await driver.writeTable(pool, { schemaName, pureName }, options);
|
return await driver.writeTable(pool, { schemaName, pureName }, options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createQuery(resFileName, typeFields) {
|
createQuery(resFileName, typeFields) {
|
||||||
return super
|
const query = super.createQuery(sql[resFileName], typeFields);
|
||||||
.createQuery(sql[resFileName], typeFields)
|
if (query) return query.replace('#REFTABLECOND#', this.driver.__analyserInternals.refTableCond);
|
||||||
.replace('#REFTABLECOND#', this.driver.__analyserInternals.refTableCond);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _computeSingleObjectId() {
|
async _computeSingleObjectId() {
|
||||||
|
|||||||
Reference in New Issue
Block a user