Skip to content

Commit 8180703

Browse files
authored
Optimized code for database-sqlsever. (#7719)
1 parent d1a35fa commit 8180703

File tree

6 files changed

+14
-55
lines changed

6 files changed

+14
-55
lines changed

src/Query/Grammars/SqlServerGrammar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Hyperf\Database\Query\Builder;
1717
use Hyperf\Database\Query\Expression;
1818
use Hyperf\Database\Query\Grammars\Grammar;
19-
use Hyperf\Database\Sqlsrv\Query\IndexHint;
19+
use Hyperf\Database\Query\IndexHint;
2020
use Hyperf\Stringable\Str;
2121

2222
use function Hyperf\Collection\collect;

src/Query/IndexHint.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/Query/Processors/SqlServerProcessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function processInsertGetId(Builder $query, $sql, $values, $sequence = nu
4848
*/
4949
public function processColumns(array $results): array
5050
{
51+
/* @phpstan-ignore-next-line */
5152
return array_map(function ($result) {
5253
$result = (object) $result;
5354

src/Query/SqlServerBuilder.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use Hyperf\Database\Query\Builder;
1818
use Hyperf\Database\Query\Expression;
1919
use Hyperf\Database\Query\Expression as ExpressionContract;
20+
use Hyperf\Database\Query\IndexHint;
2021
use Hyperf\Database\Sqlsrv\Exception\InvalidArgumentException;
21-
use RectorPrefix202308\Illuminate\Contracts\Database\Query\ConditionExpression;
2222

2323
use function Hyperf\Collection\head;
2424

@@ -93,11 +93,10 @@ public function offset($value): static
9393
* @param mixed $operator
9494
* @param mixed $value
9595
* @param string $boolean
96-
* @return $this
9796
*/
9897
public function where($column, $operator = null, $value = null, $boolean = 'and'): static
9998
{
100-
if ($column instanceof ConditionExpression) {
99+
if ($column instanceof Expression) {
101100
$type = 'Expression';
102101

103102
$this->wheres[] = compact('type', 'column', 'boolean');
@@ -161,14 +160,10 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
161160

162161
$type = 'Basic';
163162

164-
$columnString = ($column instanceof ExpressionContract)
165-
? $this->grammar->getValue($column)
166-
: $column;
167-
168163
// If the column is making a JSON reference we'll check to see if the value
169164
// is a boolean. If it is, we'll add the raw boolean string as an actual
170165
// value to the query to ensure this is properly handled by the query.
171-
if (str_contains($columnString, '->') && is_bool($value)) {
166+
if (str_contains($column, '->') && is_bool($value)) {
172167
$value = new Expression($value ? 'true' : 'false');
173168

174169
if (is_string($column)) {
@@ -211,7 +206,7 @@ public function having($column, $operator = null, $value = null, $boolean = 'and
211206
{
212207
$type = 'Basic';
213208

214-
if ($column instanceof ConditionExpression) {
209+
if ($column instanceof Expression) {
215210
$type = 'Expression';
216211

217212
$this->havings[] = compact('type', 'column', 'boolean');
@@ -328,8 +323,6 @@ public function orWhereJsonDoesntContainKey(string $column): static
328323

329324
/**
330325
* Add an index hint to suggest a query index.
331-
*
332-
* @return $this
333326
*/
334327
public function useIndex(string $index): static
335328
{
@@ -340,8 +333,6 @@ public function useIndex(string $index): static
340333

341334
/**
342335
* Add an index hint to force a query index.
343-
*
344-
* @return $this
345336
*/
346337
public function forceIndex(string $index): static
347338
{
@@ -352,8 +343,6 @@ public function forceIndex(string $index): static
352343

353344
/**
354345
* Add an index hint to ignore a query index.
355-
*
356-
* @return $this
357346
*/
358347
public function ignoreIndex(string $index): static
359348
{

src/Schema/Grammars/SqlServerGrammar.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ protected function typeTimeTz(Fluent $column): string
772772
protected function typeTimestamp(Fluent $column): string
773773
{
774774
if ($column->useCurrent) {
775+
/* @phpstan-ignore-next-line */
775776
$column->default(new Expression('CURRENT_TIMESTAMP'));
776777
}
777778

@@ -786,6 +787,7 @@ protected function typeTimestamp(Fluent $column): string
786787
protected function typeTimestampTz(Fluent $column): string
787788
{
788789
if ($column->useCurrent) {
790+
/* @phpstan-ignore-next-line */
789791
$column->default(new Expression('CURRENT_TIMESTAMP'));
790792
}
791793

@@ -897,14 +899,14 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column)
897899

898900
/**
899901
* Get the SQL for an auto-increment column modifier.
900-
*
901-
* @return null|string
902902
*/
903-
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
903+
protected function modifyIncrement(Blueprint $blueprint, Fluent $column): ?string
904904
{
905905
if (! $column->change && in_array($column->type, $this->serials) && $column->autoIncrement) {
906906
return ' identity primary key';
907907
}
908+
909+
return null;
908910
}
909911

910912
/**

src/SqlServerConnection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Closure;
1616
use Hyperf\Database\Connection;
17+
use Hyperf\Database\Grammar;
1718
use Hyperf\Database\Sqlsrv\Query\Grammars\SqlServerGrammar as QueryGrammar;
1819
use Hyperf\Database\Sqlsrv\Query\Processors\SqlServerProcessor;
1920
use Hyperf\Database\Sqlsrv\Query\SqlServerBuilder as QueryBuilder;
@@ -104,7 +105,8 @@ protected function getDefaultQueryGrammar(): QueryGrammar
104105
}
105106

106107
/**
107-
* Get the default schema grammar instance.
108+
* Set the table prefix and return the grammar.
109+
* @return Grammar&SchemaGrammar
108110
*/
109111
protected function getDefaultSchemaGrammar(): SchemaGrammar
110112
{

0 commit comments

Comments
 (0)