Skip to content

Commit

Permalink
feat: Add where clause support to Iseed class and update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tihomiro committed Feb 13, 2025
1 parent 5e50522 commit 8f19709
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Orangehill/Iseed/Iseed.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function readStubFile($file)
* @return bool
* @throws Orangehill\Iseed\TableNotFoundException
*/
public function generateSeed($table, $prefix=null, $suffix=null, $database = null, $max = 0, $chunkSize = 0, $exclude = null, $prerunEvent = null, $postrunEvent = null, $dumpAuto = true, $indexed = true, $orderBy = null, $direction = 'ASC')
public function generateSeed($table, $prefix=null, $suffix=null, $database = null, $max = 0, $chunkSize = 0, $exclude = null, $prerunEvent = null, $postrunEvent = null, $dumpAuto = true, $indexed = true, $orderBy = null, $direction = 'ASC', $whereClause = null)
{
if (!$database) {
$database = config('database.default');
Expand All @@ -75,7 +75,7 @@ public function generateSeed($table, $prefix=null, $suffix=null, $database = nul
}

// Get the data
$data = $this->getData($table, $max, $exclude, $orderBy, $direction);
$data = $this->getData($table, $max, $exclude, $orderBy, $direction, $whereClause);

// Repack the data
$dataArray = $this->repackSeedData($data);
Expand Down Expand Up @@ -130,7 +130,7 @@ public function getSeedPath()
* @param string $table
* @return Array
*/
public function getData($table, $max, $exclude = null, $orderBy = null, $direction = 'ASC')
public function getData($table, $max, $exclude = null, $orderBy = null, $direction = 'ASC', $whereClause = null)
{
$result = \DB::connection($this->databaseName)->table($table);

Expand All @@ -139,6 +139,10 @@ public function getData($table, $max, $exclude = null, $orderBy = null, $directi
$result = $result->select(array_diff($allColumns, $exclude));
}

if ($whereClause) {
$result = $result->whereRaw($whereClause);
}

if($orderBy) {
$result = $result->orderBy($orderBy, $direction);
}
Expand Down

0 comments on commit 8f19709

Please sign in to comment.