From f82805ffc66684b201176ac148ea045b6b76d733 Mon Sep 17 00:00:00 2001 From: Pedro Martins Date: Wed, 11 Aug 2021 18:10:46 +0100 Subject: [PATCH] configurable chunk size (#92) --- README.md | 7 +++++++ src/Sushi.php | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 59ddb08..70321c5 100644 --- a/README.md +++ b/README.md @@ -168,3 +168,10 @@ class Currency extends Model } } ``` + +### Troubleshoot + +**ERROR:** `SQLSTATE[HY000]: General error: 1 too many SQL variables` + +By default Sushi uses chunks of `100` to insert your data in the SQLite database. In some scenarios this might hit some SQLite limits. +You can configure the chunk size in the model: `public $sushiInsertChunkSize = 50;` \ No newline at end of file diff --git a/src/Sushi.php b/src/Sushi.php index 6f9f963..7db0e97 100644 --- a/src/Sushi.php +++ b/src/Sushi.php @@ -105,7 +105,7 @@ public function migrate() $this->createTableWithNoData($tableName); } - foreach (array_chunk($rows, 100) ?? [] as $inserts) { + foreach (array_chunk($rows, $this->getSushiInsertChunkSize()) ?? [] as $inserts) { if (!empty($inserts)) { static::insert($inserts); } @@ -187,4 +187,8 @@ public function usesTimestamps() ? parent::usesTimestamps() : false; } + + public function getSushiInsertChunkSize() { + return $this->sushiInsertChunkSize ?? 100; + } }