mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
oracle: bulk inserter
This commit is contained in:
parent
1c03a8ce9e
commit
f4fbb28124
@ -0,0 +1,38 @@
|
||||
const { createBulkInsertStreamBase } = require('dbgate-tools');
|
||||
const _ = require('lodash');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('dbgate-types').EngineDriver} driver
|
||||
*/
|
||||
function createOracleBulkInsertStream(driver, stream, pool, name, options) {
|
||||
const fullNameQuoted = name.schemaName
|
||||
? `${driver.dialect.quoteIdentifier(name.schemaName)}.${driver.dialect.quoteIdentifier(name.pureName)}`
|
||||
: driver.dialect.quoteIdentifier(name.pureName);
|
||||
|
||||
const writable = createBulkInsertStreamBase(driver, stream, pool, name, {
|
||||
...options,
|
||||
// this is really not used, send method below is used instead
|
||||
commitAfterInsert: true,
|
||||
});
|
||||
|
||||
writable.send = async () => {
|
||||
const dmp = driver.createDumper();
|
||||
dmp.putRaw(`INSERT INTO ${fullNameQuoted} (`);
|
||||
dmp.putCollection(',', writable.columnNames, col => dmp.putRaw(driver.dialect.quoteIdentifier(col)));
|
||||
dmp.putRaw(')\n VALUES (\n');
|
||||
dmp.put(
|
||||
'%,s',
|
||||
writable.columnNames.map((c, i) => `:C${i}`)
|
||||
);
|
||||
dmp.putRaw(')');
|
||||
|
||||
const rows = writable.buffer.map(row => _.mapKeys(row, (v, k) => `c${writable.columnNames.indexOf(k)}`));
|
||||
await pool.executeMany(dmp.s, rows, { autoCommit: true });
|
||||
writable.buffer = [];
|
||||
};
|
||||
|
||||
return writable;
|
||||
}
|
||||
|
||||
module.exports = createOracleBulkInsertStream;
|
@ -6,6 +6,7 @@ const Analyser = require('./Analyser');
|
||||
//--const pg = require('pg');
|
||||
const oracledb = require('oracledb');
|
||||
const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
|
||||
const createOracleBulkInsertStream = require('./createOracleBulkInsertStream');
|
||||
|
||||
/*
|
||||
pg.types.setTypeParser(1082, 'text', val => val); // date
|
||||
@ -288,8 +289,7 @@ const drivers = driverBases.map(driverBase => ({
|
||||
return pass;
|
||||
},
|
||||
async writeTable(pool, name, options) {
|
||||
// @ts-ignore
|
||||
return createBulkInsertStreamBase(this, stream, pool, name, { ...options, commitAfterInsert: true });
|
||||
return createOracleBulkInsertStream(this, stream, pool, name, options);
|
||||
},
|
||||
async listDatabases(client) {
|
||||
const { rows } = await this.query(client, 'SELECT username as "name" from all_users order by username');
|
||||
|
Loading…
Reference in New Issue
Block a user