Browse Source

fix: reduce batch size in sqlite to avoid `too many SQL variables` error

Signed-off-by: Pranav C <pranavxc@gmail.com>
feat/0523-export-schema
Pranav C 3 years ago committed by Raju Udava
parent
commit
8439c8aa57
  1. 14
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts

14
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts

@ -1528,8 +1528,13 @@ class BaseModelSqlv2 {
await this.validate(data); 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 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); .returning(this.model.primaryKey?.column_name);
// await this.afterInsertb(insertDatas, null); // await this.afterInsertb(insertDatas, null);
@ -1834,7 +1839,12 @@ class BaseModelSqlv2 {
if (!validate) continue; if (!validate) continue;
const { func, msg } = validate; const { func, msg } = validate;
for (let j = 0; j < func.length; ++j) { 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 = const arg =
typeof func[j] === 'string' ? columns[cn] + '' : columns[cn]; typeof func[j] === 'string' ? columns[cn] + '' : columns[cn];
if ( if (

Loading…
Cancel
Save