File tree Expand file tree Collapse file tree 6 files changed +96
-0
lines changed Expand file tree Collapse file tree 6 files changed +96
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,12 @@ Check MD [online][check-online].
9
9
10
10
## [ unreleased]
11
11
12
+ ## [ 2.1.0] - 2024-07-22
13
+
14
+ ### Added
15
+
16
+ - Add ` TextArrayType `
17
+
12
18
## [ 2.0.0] - 2024-03-13
13
19
14
20
### Added
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ composer require efureev/laravel-support-db "^2.0"
29
29
- [ XML] ( #xml )
30
30
- [ Array of UUID] ( #array-of-uuid )
31
31
- [ Array of Integer] ( #array-of-integer )
32
+ - [ Array of Text] ( #array-of-text )
32
33
- [ Column Options] ( #column-options )
33
34
- [ Compression] ( #compression )
34
35
- [ Views] ( #views )
@@ -159,6 +160,14 @@ The array of integer data type can be used to store a list of integers.
159
160
$table->intArray(string $column);
160
161
```
161
162
163
+ #### Array of Text
164
+
165
+ The array of text data type can be used to store a list of string.
166
+
167
+ ``` php
168
+ $table->textArray(string $column);
169
+ ```
170
+
162
171
### Column Options
163
172
164
173
#### Compression
Original file line number Diff line number Diff line change @@ -137,6 +137,14 @@ public function uuidArray(string $column): ColumnDefinition
137
137
return $ this ->addColumn ('uuidArray ' , $ column );
138
138
}
139
139
140
+ /**
141
+ * Create a new text[] column
142
+ */
143
+ public function textArray (string $ column ): ColumnDefinition
144
+ {
145
+ return $ this ->addColumn ('textArray ' , $ column );
146
+ }
147
+
140
148
/**
141
149
* Create a new int[] column
142
150
*
Original file line number Diff line number Diff line change 11
11
use Php \Support \Laravel \Database \Schema \Postgres \Types \IntArrayType ;
12
12
use Php \Support \Laravel \Database \Schema \Postgres \Types \IpNetworkType ;
13
13
use Php \Support \Laravel \Database \Schema \Postgres \Types \NumericType ;
14
+ use Php \Support \Laravel \Database \Schema \Postgres \Types \TextArrayType ;
14
15
use Php \Support \Laravel \Database \Schema \Postgres \Types \TsRangeType ;
15
16
use Php \Support \Laravel \Database \Schema \Postgres \Types \UuidArrayType ;
16
17
use Php \Support \Laravel \Database \Schema \Postgres \Types \XmlType ;
@@ -48,6 +49,11 @@ protected function typeUuidArray(ColumnDefinition $column): string
48
49
return UuidArrayType::TYPE_NAME ;
49
50
}
50
51
52
+ protected function typeTextArray (ColumnDefinition $ column ): string
53
+ {
54
+ return TextArrayType::TYPE_NAME ;
55
+ }
56
+
51
57
protected function typeIntArray (ColumnDefinition $ column ): string
52
58
{
53
59
return IntArrayType::TYPE_NAME ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Php \Support \Laravel \Database \Schema \Postgres \Types ;
6
+
7
+ class TextArrayType extends AbstractType
8
+ {
9
+ public const TYPE_NAME = 'text[] ' ;
10
+
11
+ public function phpType (): string
12
+ {
13
+ return 'text[] ' ;
14
+ }
15
+
16
+ public function postgresType (): string
17
+ {
18
+ return 'ARRAY ' ;
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Functional \Types ;
6
+
7
+ use Illuminate \Support \Facades \DB ;
8
+ use Illuminate \Support \Facades \Schema ;
9
+ use Php \Support \Laravel \Database \Schema \Postgres \Blueprint ;
10
+ use Php \Support \Laravel \Database \Schema \Postgres \Types \TextArrayType ;
11
+ use Php \Support \Laravel \Database \Schema \Postgres \Types \UuidArrayType ;
12
+ use Php \Support \Laravel \Database \Tests \AbstractTestCase ;
13
+ use Php \Support \Laravel \Database \Tests \Helpers \ColumnAssertions ;
14
+ use Php \Support \Laravel \Database \Tests \Helpers \IndexAssertions ;
15
+ use PHPUnit \Framework \Attributes \Test ;
16
+
17
+ class ArrayOfTextTest extends AbstractTestCase
18
+ {
19
+ use ColumnAssertions;
20
+ use IndexAssertions;
21
+
22
+ #[Test]
23
+ public function base (): void
24
+ {
25
+ Schema::create (
26
+ 'test_table ' ,
27
+ static function (Blueprint $ table ) {
28
+ $ table ->increments ('id ' );
29
+ $ table ->textArray ('test_col ' );
30
+ $ table ->ginIndex ('test_col ' );
31
+ }
32
+ );
33
+
34
+ static ::assertTrue (Schema::hasTable ('test_table ' ));
35
+ $ this ->seeIndex ('test_table_test_col_index ' );
36
+
37
+ $ definition = DB ::selectOne ('SELECT * FROM pg_indexes WHERE indexname = ? ' , ['test_table_test_col_index ' ]);
38
+
39
+ self ::assertEquals (
40
+ "CREATE INDEX test_table_test_col_index ON public.test_table USING gin (test_col) " ,
41
+ $ definition ->indexdef
42
+ );
43
+
44
+ $ this ->assertTypeColumn ('test_table ' , 'test_col ' , TextArrayType::class);
45
+ }
46
+
47
+ }
You can’t perform that action at this time.
0 commit comments