mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 12:06:00 +00:00
oracle: bulk inserter
This commit is contained in:
@@ -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 pg = require('pg');
|
||||||
const oracledb = require('oracledb');
|
const oracledb = require('oracledb');
|
||||||
const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
|
const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
|
||||||
|
const createOracleBulkInsertStream = require('./createOracleBulkInsertStream');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
pg.types.setTypeParser(1082, 'text', val => val); // date
|
pg.types.setTypeParser(1082, 'text', val => val); // date
|
||||||
@@ -288,8 +289,7 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
return pass;
|
return pass;
|
||||||
},
|
},
|
||||||
async writeTable(pool, name, options) {
|
async writeTable(pool, name, options) {
|
||||||
// @ts-ignore
|
return createOracleBulkInsertStream(this, stream, pool, name, options);
|
||||||
return createBulkInsertStreamBase(this, stream, pool, name, { ...options, commitAfterInsert: true });
|
|
||||||
},
|
},
|
||||||
async listDatabases(client) {
|
async listDatabases(client) {
|
||||||
const { rows } = await this.query(client, 'SELECT username as "name" from all_users order by username');
|
const { rows } = await this.query(client, 'SELECT username as "name" from all_users order by username');
|
||||||
|
|||||||
Reference in New Issue
Block a user