sqlite bulk insert

This commit is contained in:
Jan Prochazka 2021-05-06 15:57:50 +02:00
parent 23940aa324
commit 7a008e5a9d
3 changed files with 24 additions and 11 deletions

View File

@ -25,7 +25,9 @@ export const driverBase = {
analyser.singleObjectFilter = { ...name, typeField };
const res = await analyser.fullAnalysis();
if (res[typeField].length == 1) return res[typeField][0];
return res[typeField].find(x => x.pureName == name.pureName && x.schemaName == name.schemaName);
const obj = res[typeField].find(x => x.pureName == name.pureName && x.schemaName == name.schemaName);
// console.log('FIND', name, obj);
return obj;
},
analyseSingleTable(pool, name) {
return this.analyseSingleObject(pool, name, 'tables');

View File

@ -24,8 +24,10 @@ class Analyser extends DatabaseAnalyser {
'tables',
tables.rows.map((x) => x.name)
)) {
const info = await this.driver.query(this.pool, `pragma table_info('${tableName}')`);
const tableObj = tableList.find((x) => x.pureName == tableName);
if (!tableObj) continue;
const info = await this.driver.query(this.pool, `pragma table_info('${tableName}')`);
tableObj.columns = info.rows.map((col) => ({
columnName: col.name,
dataType: col.type,

View File

@ -3,6 +3,7 @@ const stream = require('stream');
const driverBase = require('../frontend/driver');
const Analyser = require('./Analyser');
const { identify } = require('sql-query-identifier');
const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
let Database;
@ -59,15 +60,23 @@ const driver = {
async query(pool, sql) {
const stmt = pool.prepare(sql);
// stmt.raw();
const columns = stmt.columns();
const rows = stmt.all();
return {
rows,
columns: columns.map((col) => ({
columnName: col.name,
dataType: col.type,
})),
};
if (stmt.reader) {
const columns = stmt.columns();
const rows = stmt.all();
return {
rows,
columns: columns.map((col) => ({
columnName: col.name,
dataType: col.type,
})),
};
} else {
stmt.run();
return {
rows: [],
columns: [],
};
}
},
async stream(client, sql, options) {
const sqlSplitted = identify(sql, { dialect: 'sqlite', strict: false });