mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 12:03:58 +00:00
clickhouse import
This commit is contained in:
@@ -10,6 +10,7 @@ export function prepareTableForImport(table: TableInfo): TableInfo {
|
|||||||
res.uniques = [];
|
res.uniques = [];
|
||||||
res.checks = [];
|
res.checks = [];
|
||||||
if (res.primaryKey) res.primaryKey.constraintName = null;
|
if (res.primaryKey) res.primaryKey.constraintName = null;
|
||||||
|
res.tableEngine = null;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,15 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
views: tableModificationsQueryData.rows.filter((x) => x.tableEngine == 'View'),
|
views: tableModificationsQueryData.rows.filter((x) => x.tableEngine == 'View'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _computeSingleObjectId() {
|
||||||
|
const { pureName } = this.singleObjectFilter;
|
||||||
|
const resId = await this.driver.query(
|
||||||
|
this.pool,
|
||||||
|
`SELECT uuid as id FROM system.tables WHERE database = '${this.pool._database_name}' AND name='${pureName}'`
|
||||||
|
);
|
||||||
|
this.singleObjectId = resId.rows[0].id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Analyser;
|
module.exports = Analyser;
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
const { createBulkInsertStreamBase } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import('dbgate-types').EngineDriver} driver
|
||||||
|
*/
|
||||||
|
function createOracleBulkInsertStream(driver, stream, pool, name, options) {
|
||||||
|
const writable = createBulkInsertStreamBase(driver, stream, pool, name, {
|
||||||
|
...options,
|
||||||
|
// this is really not used, send method below is used instead
|
||||||
|
commitAfterInsert: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
writable.send = async () => {
|
||||||
|
await pool.insert({
|
||||||
|
table: name.pureName,
|
||||||
|
values: writable.buffer,
|
||||||
|
format: 'JSONEachRow',
|
||||||
|
});
|
||||||
|
writable.buffer = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
return writable;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = createOracleBulkInsertStream;
|
||||||
@@ -3,6 +3,7 @@ const stream = require('stream');
|
|||||||
const driverBase = require('../frontend/driver');
|
const driverBase = require('../frontend/driver');
|
||||||
const Analyser = require('./Analyser');
|
const Analyser = require('./Analyser');
|
||||||
const { createClient } = require('@clickhouse/client');
|
const { createClient } = require('@clickhouse/client');
|
||||||
|
const createBulkInsertStream = require('./createBulkInsertStream');
|
||||||
|
|
||||||
/** @type {import('dbgate-types').EngineDriver} */
|
/** @type {import('dbgate-types').EngineDriver} */
|
||||||
const driver = {
|
const driver = {
|
||||||
@@ -183,9 +184,8 @@ const driver = {
|
|||||||
|
|
||||||
return pass;
|
return pass;
|
||||||
},
|
},
|
||||||
// called when importing into table or view
|
async writeTable(pool, name, options) {
|
||||||
async writeTable(connection, name, options) {
|
return createBulkInsertStream(this, stream, pool, name, options);
|
||||||
return createBulkInsertStreamBase(this, stream, pool, name, options);
|
|
||||||
},
|
},
|
||||||
// detect server version
|
// detect server version
|
||||||
async getVersion(client) {
|
async getVersion(client) {
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ class Dumper extends SqlDumper {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autoIncrement() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Dumper;
|
module.exports = Dumper;
|
||||||
|
|||||||
Reference in New Issue
Block a user