Skip to content

Commit

Permalink
feat: Add where clause support with documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tihomiro committed Feb 13, 2025
1 parent 171281b commit 5e50522
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@ Example:
php artisan iseed users --noindex
```

### where
Optional parameter which allows you to specify a SQL WHERE clause to filter the rows that will be included in the seed file. The WHERE clause should be provided as a string and will be applied directly to the SQL query.

Examples:
```sh
# Only seed users with example.com emails
php artisan iseed users --where="email LIKE '%@example.com'"

# Seed active users created after a specific date
php artisan iseed users --where="active = 1 AND created_at > '2024-01-01'"

# Combine with other options
php artisan iseed users --where="role = 'admin'" --max=10 --orderby=created_at --direction=desc
```

**Note**: When using complex WHERE clauses with special characters or spaces, make sure to properly escape and quote the condition string according to your shell's requirements.

## Usage

To generate a seed file for your users table simply call: `\Iseed::generateSeed('users', 'connectionName', 'numOfRows');`. `connectionName` and `numOfRows` are not required arguments.
Expand Down
10 changes: 8 additions & 2 deletions src/Orangehill/Iseed/IseedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function fire()
$direction = $this->option('direction');
$prefix = $this->option('classnameprefix');
$suffix = $this->option('classnamesuffix');
$whereClause = $this->option('where');

if ($max < 1) {
$max = null;
Expand Down Expand Up @@ -108,7 +109,8 @@ public function fire()
$dumpAuto,
$indexed,
$orderBy,
$direction
$direction,
$whereClause
),
$table
);
Expand All @@ -129,7 +131,10 @@ public function fire()
$prerunEvent,
$postrunEvent,
$dumpAuto,
$indexed
$indexed,
$orderBy,
$direction,
$whereClause
),
$table
);
Expand Down Expand Up @@ -172,6 +177,7 @@ protected function getOptions()
array('direction', null, InputOption::VALUE_OPTIONAL, 'orderby direction', null),
array('classnameprefix', null, InputOption::VALUE_OPTIONAL, 'prefix for class and file name', null),
array('classnamesuffix', null, InputOption::VALUE_OPTIONAL, 'suffix for class and file name', null),
array('where', null, InputOption::VALUE_OPTIONAL, 'where clause to filter records', null),
);
}

Expand Down

0 comments on commit 5e50522

Please sign in to comment.