Skip to content

Commit 77cc3fe

Browse files
committed
Add per-column sort key direction feature
1 parent afbd7be commit 77cc3fe

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Schema/Grammar.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Database\Schema\Grammars\MySqlGrammar;
1212
use Illuminate\Support\Fluent;
1313
use Illuminate\Support\Str;
14+
use InvalidArgumentException;
1415
use SingleStore\Laravel\Schema\Blueprint as SingleStoreBlueprint;
1516
use SingleStore\Laravel\Schema\Grammar\CompilesKeys;
1617
use SingleStore\Laravel\Schema\Grammar\ModifiesColumns;
@@ -185,9 +186,27 @@ protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
185186
*/
186187
protected function columnizeWithDirection(array $columns, string $direction)
187188
{
189+
if ($columns === array_filter($columns, 'is_array')) {
190+
$columnNames = array_map(function ($column) {
191+
return $this->wrap($column[0]);
192+
}, $columns);
193+
194+
$columnDirections = array_map(function ($column) {
195+
return $column[1];
196+
}, $columns);
197+
198+
return implode(', ', array_map(function ($column, $direction) {
199+
return "$column $direction";
200+
}, $columnNames, $columnDirections));
201+
}
202+
188203
$wrapped = array_map([$this, 'wrap'], $columns);
189204

190205
return implode(', ', array_map(function ($column) use ($direction) {
206+
if (is_array($column)) {
207+
throw new InvalidArgumentException('You must set the direction for each key column or use the second parameter to set the direction for all key columns');
208+
}
209+
191210
return $column.' '.$direction;
192211
}, $wrapped));
193212
}

0 commit comments

Comments
 (0)