Skip to content

Commit 71d4e20

Browse files
committed
Add support for sort key desc
1 parent 662ac36 commit 71d4e20

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

src/Schema/Blueprint/InlinesIndexes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ trait InlinesIndexes
1818
protected $singleStoreIndexes = [
1919
'shardKey',
2020
'sortKey',
21+
'sortKeyDesc'
2122
];
2223

2324
/**
@@ -81,7 +82,8 @@ protected function inlineCreateIndexStatements($statements)
8182
protected function indexCommands()
8283
{
8384
return $this->commandsNamed(array_merge(
84-
$this->singleStoreIndexes, $this->mysqlIndexes
85+
$this->singleStoreIndexes,
86+
$this->mysqlIndexes
8587
));
8688
}
8789

src/Schema/Blueprint/ModifiesIndexes.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ public function sortKey($columns, $name = null)
2929
return $this->indexCommand('sortKey', $columns, $name);
3030
}
3131

32+
/**
33+
* @param $columns
34+
* @param $name
35+
* @return \Illuminate\Support\Fluent
36+
*/
37+
public function sortKeyDesc($columns, $name = null)
38+
{
39+
return $this->indexCommand('sortKeyDesc', $columns, $name);
40+
}
41+
3242
/**
3343
* @param $columns
3444
* @param $name

src/Schema/Grammar/CompilesKeys.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public function compileSortKey(Blueprint $blueprint, Fluent $command)
2020
return "sort key({$this->columnize($command->columns)})";
2121
}
2222

23+
public function compileSortKeyDesc(Blueprint $blueprint, Fluent $command)
24+
{
25+
return "sort key({$this->columnize($command->columns)} desc)";
26+
}
27+
2328
public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
2429
{
2530
// SingleStore's spatial indexes just use the keyword `index`, not `spatial index`.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* @author Aaron Francis <aarondfrancis@gmail.com|https://twitter.com/aarondfrancis>
4+
*/
5+
6+
namespace SingleStore\Laravel\Tests\Hybrid\CreateTable;
7+
8+
use SingleStore\Laravel\Schema\Blueprint;
9+
use SingleStore\Laravel\Tests\BaseTest;
10+
use SingleStore\Laravel\Tests\Hybrid\HybridTestHelpers;
11+
12+
class SortKeysDescTest extends BaseTest
13+
{
14+
use HybridTestHelpers;
15+
16+
/** @test */
17+
public function it_adds_a_sort_key_desc_standalone()
18+
{
19+
$blueprint = $this->createTable(function (Blueprint $table) {
20+
$table->string('name');
21+
$table->sortKeyDesc('name');
22+
});
23+
24+
$this->assertCreateStatement(
25+
$blueprint,
26+
'create table `test` (`name` varchar(255) not null, sort key(`name` desc))'
27+
);
28+
}
29+
30+
/** @test */
31+
public function it_adds_a_sort_key_desc_fluent()
32+
{
33+
$blueprint = $this->createTable(function (Blueprint $table) {
34+
$table->string('name')->sortKey();
35+
});
36+
37+
$this->assertCreateStatement(
38+
$blueprint,
39+
'create table `test` (`name` varchar(255) not null, sort key(`name` desc))'
40+
);
41+
}
42+
43+
/** @test */
44+
public function it_adds_a_dual_sort_key_desc()
45+
{
46+
$blueprint = $this->createTable(function (Blueprint $table) {
47+
$table->string('f_name');
48+
$table->string('l_name');
49+
$table->sortKeyDesc(['f_name', 'l_name']);
50+
});
51+
52+
$this->assertCreateStatement(
53+
$blueprint,
54+
'create table `test` (`f_name` varchar(255) not null, `l_name` varchar(255) not null, sort key(`f_name`, `l_name` desc))'
55+
);
56+
}
57+
58+
/** @test */
59+
public function shard_and_sort_keys_desc()
60+
{
61+
$blueprint = $this->createTable(function (Blueprint $table) {
62+
$table->string('name')->sortKeyDesc()->shardKey();
63+
});
64+
65+
$this->assertCreateStatement(
66+
$blueprint,
67+
'create table `test` (`name` varchar(255) not null, shard key(`name`), sort key(`name` desc))'
68+
);
69+
}
70+
}

0 commit comments

Comments
 (0)