File tree Expand file tree Collapse file tree 5 files changed +109
-1
lines changed Expand file tree Collapse file tree 5 files changed +109
-1
lines changed Original file line number Diff line number Diff line change @@ -256,10 +256,12 @@ BlogArticle::select([
256
256
#### String
257
257
``` php
258
258
use Tpetry\QueryExpressions\Function\String\{
259
- Concat, Uuid4
259
+ Concat, Lower, Upper, Uuid4
260
260
};
261
261
262
262
new Concat(array $expressions);
263
+ new Lower(string|Expression $expression);
264
+ new Upper(string|Expression $expression);
263
265
new Uuid4();
264
266
265
267
Schema::table('users', function (Blueprint $table): void {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Tpetry \QueryExpressions \Function \String ;
6
+
7
+ use Illuminate \Contracts \Database \Query \Expression ;
8
+ use Illuminate \Database \Grammar ;
9
+ use Tpetry \QueryExpressions \Concerns \IdentifiesDriver ;
10
+ use Tpetry \QueryExpressions \Concerns \StringizeExpression ;
11
+
12
+ class Lower implements Expression
13
+ {
14
+ use IdentifiesDriver;
15
+ use StringizeExpression;
16
+
17
+ public function __construct (
18
+ private readonly string |Expression $ expression ,
19
+ ) {
20
+ }
21
+
22
+ public function getValue (Grammar $ grammar ): string
23
+ {
24
+ $ expression = $ this ->stringize ($ grammar , $ this ->expression );
25
+
26
+ return match ($ this ->identify ($ grammar )) {
27
+ 'mysql ' , 'sqlite ' => "(lower( {$ expression })) " ,
28
+ 'pgsql ' , 'sqlsrv ' => "lower( {$ expression }) " ,
29
+ };
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Tpetry \QueryExpressions \Function \String ;
6
+
7
+ use Illuminate \Contracts \Database \Query \Expression ;
8
+ use Illuminate \Database \Grammar ;
9
+ use Tpetry \QueryExpressions \Concerns \IdentifiesDriver ;
10
+ use Tpetry \QueryExpressions \Concerns \StringizeExpression ;
11
+
12
+ class Upper implements Expression
13
+ {
14
+ use IdentifiesDriver;
15
+ use StringizeExpression;
16
+
17
+ public function __construct (
18
+ private readonly string |Expression $ expression ,
19
+ ) {
20
+ }
21
+
22
+ public function getValue (Grammar $ grammar ): string
23
+ {
24
+ $ expression = $ this ->stringize ($ grammar , $ this ->expression );
25
+
26
+ return match ($ this ->identify ($ grammar )) {
27
+ 'mysql ' , 'sqlite ' => "(upper( {$ expression })) " ,
28
+ 'pgsql ' , 'sqlsrv ' => "upper( {$ expression }) " ,
29
+ };
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ use Illuminate \Database \Query \Expression ;
6
+ use Tpetry \QueryExpressions \Function \String \Lower ;
7
+
8
+ it ('can lowercase a column ' )
9
+ ->expect (new Lower ('val ' ))
10
+ ->toBeExecutable (['val varchar(255) ' ])
11
+ ->toBeMysql ('(lower(`val`)) ' )
12
+ ->toBePgsql ('lower("val") ' )
13
+ ->toBeSqlite ('(lower("val")) ' )
14
+ ->toBeSqlsrv ('lower([val]) ' );
15
+
16
+ it ('can lowercase an expression ' )
17
+ ->expect (new Lower (new Expression ("'foo' " )))
18
+ ->toBeExecutable ()
19
+ ->toBeMysql ("(lower('foo')) " )
20
+ ->toBePgsql ("lower('foo') " )
21
+ ->toBeSqlite ("(lower('foo')) " )
22
+ ->toBeSqlsrv ("lower('foo') " );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ use Illuminate \Database \Query \Expression ;
6
+ use Tpetry \QueryExpressions \Function \String \Upper ;
7
+
8
+ it ('can uppercase a column ' )
9
+ ->expect (new Upper ('val ' ))
10
+ ->toBeExecutable (['val varchar(255) ' ])
11
+ ->toBeMysql ('(upper(`val`)) ' )
12
+ ->toBePgsql ('upper("val") ' )
13
+ ->toBeSqlite ('(upper("val")) ' )
14
+ ->toBeSqlsrv ('upper([val]) ' );
15
+
16
+ it ('can uppercase an expression ' )
17
+ ->expect (new Upper (new Expression ("'foo' " )))
18
+ ->toBeExecutable ()
19
+ ->toBeMysql ("(upper('foo')) " )
20
+ ->toBePgsql ("upper('foo') " )
21
+ ->toBeSqlite ("(upper('foo')) " )
22
+ ->toBeSqlsrv ("upper('foo') " );
You can’t perform that action at this time.
0 commit comments