mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
sqlite bulk insert
This commit is contained in:
parent
23940aa324
commit
7a008e5a9d
@ -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');
|
||||
|
@ -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,
|
||||
|
@ -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 });
|
||||
|
Loading…
Reference in New Issue
Block a user