mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 23:06:01 +00:00
sqlite bulk insert
This commit is contained in:
@@ -25,7 +25,9 @@ export const driverBase = {
|
|||||||
analyser.singleObjectFilter = { ...name, typeField };
|
analyser.singleObjectFilter = { ...name, typeField };
|
||||||
const res = await analyser.fullAnalysis();
|
const res = await analyser.fullAnalysis();
|
||||||
if (res[typeField].length == 1) return res[typeField][0];
|
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) {
|
analyseSingleTable(pool, name) {
|
||||||
return this.analyseSingleObject(pool, name, 'tables');
|
return this.analyseSingleObject(pool, name, 'tables');
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
'tables',
|
'tables',
|
||||||
tables.rows.map((x) => x.name)
|
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);
|
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) => ({
|
tableObj.columns = info.rows.map((col) => ({
|
||||||
columnName: col.name,
|
columnName: col.name,
|
||||||
dataType: col.type,
|
dataType: col.type,
|
||||||
|
|||||||
@@ -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 { identify } = require('sql-query-identifier');
|
const { identify } = require('sql-query-identifier');
|
||||||
|
const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
|
||||||
|
|
||||||
let Database;
|
let Database;
|
||||||
|
|
||||||
@@ -59,15 +60,23 @@ const driver = {
|
|||||||
async query(pool, sql) {
|
async query(pool, sql) {
|
||||||
const stmt = pool.prepare(sql);
|
const stmt = pool.prepare(sql);
|
||||||
// stmt.raw();
|
// stmt.raw();
|
||||||
const columns = stmt.columns();
|
if (stmt.reader) {
|
||||||
const rows = stmt.all();
|
const columns = stmt.columns();
|
||||||
return {
|
const rows = stmt.all();
|
||||||
rows,
|
return {
|
||||||
columns: columns.map((col) => ({
|
rows,
|
||||||
columnName: col.name,
|
columns: columns.map((col) => ({
|
||||||
dataType: col.type,
|
columnName: col.name,
|
||||||
})),
|
dataType: col.type,
|
||||||
};
|
})),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
stmt.run();
|
||||||
|
return {
|
||||||
|
rows: [],
|
||||||
|
columns: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async stream(client, sql, options) {
|
async stream(client, sql, options) {
|
||||||
const sqlSplitted = identify(sql, { dialect: 'sqlite', strict: false });
|
const sqlSplitted = identify(sql, { dialect: 'sqlite', strict: false });
|
||||||
|
|||||||
Reference in New Issue
Block a user