From 8439c8aa57e229a0c4c191d97d3bcd557604a96f Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 28 May 2022 16:47:42 +0530 Subject: [PATCH] fix: reduce batch size in sqlite to avoid `too many SQL variables` error Signed-off-by: Pranav C --- .../src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts index 425f62535f..7bdbca02e7 100644 --- a/packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts @@ -1528,8 +1528,13 @@ class BaseModelSqlv2 { await this.validate(data); } + // fallbacks to `10` if database client is sqlite + // to avoid `too many SQL variables` error + // refer : https://www.sqlite.org/limits.html + const chunkSize = this.isSqlite ? 10 : 50; + const response = await this.dbDriver - .batchInsert(this.model.table_name, insertDatas, 50) + .batchInsert(this.model.table_name, insertDatas, chunkSize) .returning(this.model.primaryKey?.column_name); // await this.afterInsertb(insertDatas, null); @@ -1834,7 +1839,12 @@ class BaseModelSqlv2 { if (!validate) continue; const { func, msg } = validate; for (let j = 0; j < func.length; ++j) { - const fn = typeof func[j] === 'string' ? (customValidators[func[j]] ? customValidators[func[j]] : Validator[func[j]]) : func[j]; + const fn = + typeof func[j] === 'string' + ? customValidators[func[j]] + ? customValidators[func[j]] + : Validator[func[j]] + : func[j]; const arg = typeof func[j] === 'string' ? columns[cn] + '' : columns[cn]; if (