Skip to content

Commit

Permalink
configurable chunk size (calebporzio#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
pxpm authored Aug 11, 2021
1 parent 805ec70 commit f82805f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;`
6 changes: 5 additions & 1 deletion src/Sushi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -187,4 +187,8 @@ public function usesTimestamps()
? parent::usesTimestamps()
: false;
}

public function getSushiInsertChunkSize() {
return $this->sushiInsertChunkSize ?? 100;
}
}

0 comments on commit f82805f

Please sign in to comment.