Browse Source

feat: raw bulk insert for import

Signed-off-by: mertmit <mertmit99@gmail.com>
feat/export
mertmit 2 years ago
parent
commit
5452612af7
  1. 13
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts
  2. 3
      packages/nocodb/src/lib/services/dbData/bulkData.ts
  3. 19
      packages/nocodb/src/lib/services/exportImport/import.svc.ts

13
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -2067,14 +2067,17 @@ class BaseModelSqlv2 {
chunkSize: _chunkSize = 100, chunkSize: _chunkSize = 100,
cookie, cookie,
foreign_key_checks = true, foreign_key_checks = true,
raw = false,
}: { }: {
chunkSize?: number; chunkSize?: number;
cookie?: any; cookie?: any;
foreign_key_checks?: boolean; foreign_key_checks?: boolean;
raw?: boolean;
} = {} } = {}
) { ) {
try { try {
const insertDatas = await Promise.all( // TODO: ag column handling for raw bulk insert
const insertDatas = raw ? datas : await Promise.all(
datas.map(async (d) => { datas.map(async (d) => {
await populatePk(this.model, d); await populatePk(this.model, d);
return this.model.mapAliasToColumn(d); return this.model.mapAliasToColumn(d);
@ -2083,8 +2086,10 @@ class BaseModelSqlv2 {
// await this.beforeInsertb(insertDatas, null); // await this.beforeInsertb(insertDatas, null);
for (const data of datas) { if (!raw) {
await this.validate(data); for (const data of datas) {
await this.validate(data);
}
} }
// fallbacks to `10` if database client is sqlite // fallbacks to `10` if database client is sqlite
@ -2123,7 +2128,7 @@ class BaseModelSqlv2 {
await trx.commit(); await trx.commit();
await this.afterBulkInsert(insertDatas, this.dbDriver, cookie); if (!raw) await this.afterBulkInsert(insertDatas, this.dbDriver, cookie);
return response; return response;
} catch (e) { } catch (e) {

3
packages/nocodb/src/lib/services/dbData/bulkData.ts

@ -40,12 +40,13 @@ export async function bulkDataInsert(
cookie: any; cookie: any;
chunkSize?: number; chunkSize?: number;
foreign_key_checks?: boolean; foreign_key_checks?: boolean;
raw?: boolean;
} }
) { ) {
return await executeBulkOperation({ return await executeBulkOperation({
...param, ...param,
operation: 'bulkInsert', operation: 'bulkInsert',
options: [param.body, { cookie: param.cookie, foreign_key_checks: param.foreign_key_checks, chunkSize: param.chunkSize }], options: [param.body, { cookie: param.cookie, foreign_key_checks: param.foreign_key_checks, chunkSize: param.chunkSize, raw: param.raw }],
}); });
} }

19
packages/nocodb/src/lib/services/exportImport/import.svc.ts

@ -653,9 +653,9 @@ export async function importBase(param: {
base_id: baseId, base_id: baseId,
colId: col.colOptions.fk_child_column_id, colId: col.colOptions.fk_child_column_id,
}); });
headers.push(childCol.title); headers.push(childCol.column_name);
} else { } else {
headers.push(col.title); headers.push(col.column_name);
} }
} else { } else {
debugLog(header); debugLog(header);
@ -671,7 +671,7 @@ export async function importBase(param: {
} }
} }
chunk.push(row); chunk.push(row);
if (chunk.length > 1000) { if (chunk.length > 100) {
parser.pause(); parser.pause();
elapsedTime('before import chunk'); elapsedTime('before import chunk');
try { try {
@ -681,7 +681,8 @@ export async function importBase(param: {
body: chunk, body: chunk,
cookie: null, cookie: null,
chunkSize: chunk.length + 1, chunkSize: chunk.length + 1,
foreign_key_checks: false foreign_key_checks: false,
raw: true,
}); });
} catch (e) { } catch (e) {
debugLog(`${model.title} import throwed an error!`); debugLog(`${model.title} import throwed an error!`);
@ -704,7 +705,8 @@ export async function importBase(param: {
body: chunk, body: chunk,
cookie: null, cookie: null,
chunkSize: chunk.length + 1, chunkSize: chunk.length + 1,
foreign_key_checks: false foreign_key_checks: false,
raw: true,
}); });
} catch (e) { } catch (e) {
debugLog(chunk); debugLog(chunk);
@ -779,8 +781,8 @@ export async function importBase(param: {
const vParentCol = await colOptions.getMMParentColumn(); const vParentCol = await colOptions.getMMParentColumn();
mmParentChild[col.colOptions.fk_mm_model_id] = { mmParentChild[col.colOptions.fk_mm_model_id] = {
parent: vParentCol.title, parent: vParentCol.column_name,
child: vChildCol.title, child: vChildCol.column_name,
} }
handledLinks.push(col.colOptions.fk_mm_model_id); handledLinks.push(col.colOptions.fk_mm_model_id);
@ -816,7 +818,8 @@ export async function importBase(param: {
body: v, body: v,
cookie: null, cookie: null,
chunkSize: 1000, chunkSize: 1000,
foreign_key_checks: false foreign_key_checks: false,
raw: true,
}); });
elapsedTime('insert link chunk'); elapsedTime('insert link chunk');
} catch (e) { } catch (e) {

Loading…
Cancel
Save