Skip to content

Commit 6f628cd

Browse files
Merge pull request #57 from AdalbertMemSQL/issue54
Added support of the Laravel 10
2 parents ef9566a + ab47390 commit 6f628cd

File tree

9 files changed

+56
-86
lines changed

9 files changed

+56
-86
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Update VARIANT to pick a PHP version: 8, 8.1, 8.0, 7, 7.4
99
// Append -bullseye or -buster to pin to an OS version.
1010
// Use -bullseye variants on local on arm64/Apple Silicon.
11-
"VARIANT": "8"
11+
"VARIANT": "8.1"
1212
}
1313
},
1414

.github/workflows/tests.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
php: [7.3, 7.4, 8.0, 8.1]
22-
laravel: [8.*, 9.*]
22+
laravel: [8.*, 9.*, 10.*]
2323
dependency-version: [prefer-lowest, prefer-stable]
2424
include:
2525
- laravel: 8.*
@@ -28,6 +28,9 @@ jobs:
2828
- laravel: 9.*
2929
testbench: 7.*
3030

31+
- laravel: 10.*
32+
testbench: 8.*
33+
3134
exclude:
3235
# Laravel 8.0 has type incompatibilities with PHP 8.1.
3336
- laravel: 8.*
@@ -41,6 +44,16 @@ jobs:
4144
- laravel: 9.*
4245
php: 7.4
4346

47+
# Laravel 10 requires PHP 8.1
48+
- laravel: 10.*
49+
php: 7.3
50+
51+
- laravel: 10.*
52+
php: 7.4
53+
54+
- laravel: 10.*
55+
php: 8.0
56+
4457
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
4558

4659
services:

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
],
2626
"require": {
2727
"php": "^7.3|^8.0",
28-
"illuminate/container": "^8.0|^9.0",
29-
"illuminate/database": "^8.0|^9.0",
30-
"illuminate/events": "^8.0|^9.0",
31-
"illuminate/support": "^8.0|^9.0"
28+
"illuminate/container": "^8.0|^9.0|^10.0",
29+
"illuminate/database": "^8.0|^9.0|^10.0",
30+
"illuminate/events": "^8.0|^9.0|^10.0",
31+
"illuminate/support": "^8.0|^9.0|^10.0"
3232
},
3333
"require-dev": {
3434
"mockery/mockery": "^1.5",

src/Query/Grammar.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class Grammar extends MySqlGrammar
1010
/**
1111
* Compile a "where fulltext" clause.
1212
*
13-
* @param \Illuminate\Database\Query\Builder $query
1413
* @param array $where
1514
* @return string
1615
*/
@@ -24,8 +23,6 @@ public function whereFullText(Builder $query, $where)
2423
}
2524

2625
/**
27-
* @param $column
28-
* @param $value
2926
* @return string
3027
*/
3128
protected function compileJsonContains($column, $value)
@@ -153,7 +150,6 @@ protected function wrapUnion($sql)
153150
/**
154151
* Compile the "union" queries attached to the main query.
155152
*
156-
* @param Builder $query
157153
* @return string
158154
*/
159155
protected function compileUnions(Builder $query)
@@ -170,7 +166,6 @@ protected function compileUnions(Builder $query)
170166
/**
171167
* Compile a select query into SQL.
172168
*
173-
* @param Builder $query
174169
* @return string
175170
*/
176171
public function compileSelect(Builder $query)
@@ -199,8 +194,6 @@ public function compileSelect(Builder $query)
199194
/**
200195
* Compile the "offset" portions of the query.
201196
*
202-
* @param Builder $query
203-
* @param $offset
204197
* @return string
205198
*/
206199
protected function compileOffset(Builder $query, $offset)
@@ -210,10 +203,6 @@ protected function compileOffset(Builder $query, $offset)
210203

211204
/**
212205
* Compile the "offset" portions of the final union query.
213-
*
214-
* @param Builder $query
215-
* @param $offset
216-
* @return string
217206
*/
218207
protected function compileUnionOffset(Builder $query, $offset): string
219208
{
@@ -222,10 +211,6 @@ protected function compileUnionOffset(Builder $query, $offset): string
222211

223212
/**
224213
* Compile the "offset" portions of the query taking into account "limit" portion.
225-
*
226-
* @param $offset
227-
* @param $limit
228-
* @return string
229214
*/
230215
private function compileOffsetWithLimit($offset, $limit): string
231216
{

src/Schema/Blueprint.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,9 @@ public function geographyPoint($column)
2727
return $this->point($column);
2828
}
2929

30-
public function toSql(Connection $connection, Grammar $grammar)
31-
{
32-
$statements = parent::toSql($connection, $grammar);
33-
34-
return $this->creating() ? $this->inlineCreateIndexStatements($statements) : $statements;
35-
}
36-
3730
/**
3831
* Execute the blueprint against the database.
3932
*
40-
* @param \Illuminate\Database\Connection $connection
41-
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
4233
* @return void
4334
*/
4435
public function build(Connection $connection, Grammar $grammar)

src/Schema/Blueprint/InlinesIndexes.php

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace SingleStore\Laravel\Schema\Blueprint;
44

5+
use Illuminate\Database\Connection;
56
use Illuminate\Database\Schema\Grammars\Grammar;
7+
use Illuminate\Foundation\Application;
68
use Illuminate\Support\Arr;
79
use SingleStore\Laravel\Schema\Blueprint as SingleStoreBlueprint;
810

@@ -32,30 +34,23 @@ trait InlinesIndexes
3234
'spatialIndex',
3335
];
3436

35-
/**
36-
* The keys of the commands that are indexes
37-
*
38-
* @var int[]
39-
*/
40-
protected $indexCommandKeys = [];
41-
4237
/**
4338
* Given a set of statements from the `toSQL` method, inline all
4439
* of the indexes into the CREATE TABLE statement.
4540
*
4641
* @param array $statements
4742
* @return array
4843
*/
49-
protected function inlineCreateIndexStatements($statements)
44+
protected function inlineCreateIndexStatements($statements, $indexStatementKeys)
5045
{
5146
// In the `addImpliedCommands` method we gathered up the keys of all the commands
5247
// that are index commands. Now that we're ready to compile the SQL we'll pull
5348
// all those statements out to sneak them into the CREATE TABLE statement.
54-
$indexStatements = Arr::only($statements, $this->indexCommandKeys);
49+
$indexStatements = Arr::only($statements, $indexStatementKeys);
5550

5651
// Since we're putting the index statements inside the CREATE TABLE statement,
5752
// we pull them out of the statement list so that they don't run as ALTERs.
58-
Arr::forget($statements, $this->indexCommandKeys);
53+
Arr::forget($statements, $indexStatementKeys);
5954

6055
$search = SingleStoreBlueprint::INDEX_PLACEHOLDER;
6156

@@ -72,37 +67,18 @@ protected function inlineCreateIndexStatements($statements)
7267
}
7368

7469
/**
75-
* Get all of the index commands out of the blueprint's command queue.
70+
* Check if the command is index.
7671
*
7772
* @return \Illuminate\Support\Collection
7873
*/
79-
protected function indexCommands()
74+
protected function isIndexCommand($command)
8075
{
81-
return $this->commandsNamed(array_merge(
76+
return in_array($command->name, array_merge(
8277
$this->singleStoreIndexes,
8378
$this->mysqlIndexes
8479
));
8580
}
8681

87-
/**
88-
* @param Grammar $grammar
89-
* @return void
90-
*/
91-
protected function addImpliedCommands(Grammar $grammar)
92-
{
93-
parent::addImpliedCommands($grammar);
94-
95-
$this->addFluentSingleStoreIndexes();
96-
97-
if ($this->creating()) {
98-
// We have to pull the keys for the indexes during this method because once
99-
// compiled, the primary key's `name` attribute is set to null, meaning
100-
// that we can no longer tell what type of key it is. By hooking into
101-
// the `addImpliedCommands` method, we access it before compilation.
102-
$this->indexCommandKeys = $this->indexCommands()->keys()->toArray();
103-
}
104-
}
105-
10682
/**
10783
* @return void
10884
*/
@@ -132,4 +108,33 @@ protected function addFluentSingleStoreIndexes()
132108
}
133109
}
134110
}
111+
112+
public function toSql(Connection $connection, Grammar $grammar)
113+
{
114+
if (version_compare(Application::VERSION, '10.0.0', '>=')) {
115+
$this->addImpliedCommands($connection, $grammar);
116+
} else {
117+
$this->addImpliedCommands($grammar);
118+
}
119+
$this->addFluentSingleStoreIndexes();
120+
121+
$statements = [];
122+
$indexStatementKeys = [];
123+
124+
foreach ($this->commands as $command) {
125+
$method = 'compile'.ucfirst($command->name);
126+
$isIndex = $this->isIndexCommand($command);
127+
128+
if (method_exists($grammar, $method) || $grammar::hasMacro($method)) {
129+
if (! is_null($sql = $grammar->$method($this, $command, $connection))) {
130+
$statements = array_merge($statements, (array) $sql);
131+
if ($isIndex) {
132+
array_push($indexStatementKeys, count($statements) - 1);
133+
}
134+
}
135+
}
136+
}
137+
138+
return $this->creating() ? $this->inlineCreateIndexStatements($statements, $indexStatementKeys) : $statements;
139+
}
135140
}

src/Schema/Blueprint/ModifiesIndexes.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
trait ModifiesIndexes
88
{
99
/**
10-
* @param $columns
1110
* @return \Illuminate\Support\Fluent
1211
*/
1312
public function shardKey($columns)
@@ -16,8 +15,6 @@ public function shardKey($columns)
1615
}
1716

1817
/**
19-
* @param $columns
20-
* @param $direction
2118
* @return \Illuminate\Support\Fluent
2219
*/
2320
public function sortKey($columns = null, $direction = 'asc')
@@ -29,8 +26,6 @@ public function sortKey($columns = null, $direction = 'asc')
2926
}
3027

3128
/**
32-
* @param $columns
33-
* @param $name
3429
* @return SpatialIndexCommand
3530
*/
3631
public function spatialIndex($columns, $name = null)

src/Schema/Builder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class Builder extends MySqlBuilder
99
{
1010
/**
1111
* @param string $table
12-
* @param Closure|null $callback
1312
* @return \Illuminate\Database\Schema\Blueprint
1413
*/
1514
protected function createBlueprint($table, Closure $callback = null)

src/Schema/Grammar.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public function __construct()
2828
/**
2929
* Compile a primary key command.
3030
*
31-
* @param \Illuminate\Database\Schema\Blueprint $blueprint
32-
* @param \Illuminate\Support\Fluent $command
3331
* @return string
3432
*/
3533
public function compilePrimary(Blueprint $blueprint, Fluent $command)
@@ -42,7 +40,6 @@ public function compilePrimary(Blueprint $blueprint, Fluent $command)
4240
/**
4341
* Create the column definition for a spatial Geography type.
4442
*
45-
* @param \Illuminate\Support\Fluent $column
4643
* @return string
4744
*/
4845
public function typeGeography(Fluent $column)
@@ -53,7 +50,6 @@ public function typeGeography(Fluent $column)
5350
/**
5451
* Create the column definition for a spatial Point type.
5552
*
56-
* @param \Illuminate\Support\Fluent $column
5753
* @return string
5854
*/
5955
public function typePoint(Fluent $column)
@@ -83,7 +79,6 @@ protected function compileCreateTable($blueprint, $command, $connection)
8379
}
8480

8581
/**
86-
* @param Fluent $column
8782
* @return string
8883
*/
8984
protected function getType(Fluent $column)
@@ -105,8 +100,6 @@ protected function getType(Fluent $column)
105100
* Append the engine specifications to a command.
106101
*
107102
* @param string $sql
108-
* @param \Illuminate\Database\Connection $connection
109-
* @param \Illuminate\Database\Schema\Blueprint $blueprint
110103
* @return string
111104
*/
112105
protected function compileCreateEngine($sql, Connection $connection, Blueprint $blueprint)
@@ -123,8 +116,6 @@ protected function compileCreateEngine($sql, Connection $connection, Blueprint $
123116
}
124117

125118
/**
126-
* @param $blueprint
127-
* @param $compiled
128119
* @return string
129120
*
130121
* @throws Exception
@@ -149,7 +140,6 @@ protected function insertCreateTableModifiers($blueprint, $compiled)
149140
}
150141

151142
/**
152-
* @param Blueprint $blueprint
153143
* @return array
154144
*
155145
* @throws Exception
@@ -169,9 +159,6 @@ protected function getColumns(Blueprint $blueprint)
169159
}
170160

171161
/**
172-
* @param Blueprint $blueprint
173-
* @param Fluent $command
174-
* @param $type
175162
* @return array|string|string[]
176163
*/
177164
protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
@@ -192,7 +179,6 @@ protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
192179
/**
193180
* Convert an array of column names into a delimited string (with direction parameter).
194181
*
195-
* @param array $columns
196182
* @return string
197183
*/
198184
protected function columnizeWithDirection(array $columns, string $direction)
@@ -225,8 +211,6 @@ protected function columnizeWithDirection(array $columns, string $direction)
225211
/**
226212
* Get the SQL for an auto-increment column modifier.
227213
*
228-
* @param \Illuminate\Database\Schema\Blueprint $blueprint
229-
* @param \Illuminate\Support\Fluent $column
230214
* @return string|null
231215
*/
232216
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
@@ -241,8 +225,6 @@ protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
241225
/**
242226
* Compile a rename table command.
243227
*
244-
* @param \Illuminate\Database\Schema\Blueprint $blueprint
245-
* @param \Illuminate\Support\Fluent $command
246228
* @return string
247229
*/
248230
public function compileRename(Blueprint $blueprint, Fluent $command)

0 commit comments

Comments
 (0)