Skip to content

Commit b0133eb

Browse files
author
Eugene Fureev
committed
feat: add TextArrayType
1 parent f02e957 commit b0133eb

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Check MD [online][check-online].
99

1010
## [unreleased]
1111

12+
## [2.1.0] - 2024-07-22
13+
14+
### Added
15+
16+
- Add `TextArrayType`
17+
1218
## [2.0.0] - 2024-03-13
1319

1420
### Added

readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ composer require efureev/laravel-support-db "^2.0"
2929
- [XML](#xml)
3030
- [Array of UUID](#array-of-uuid)
3131
- [Array of Integer](#array-of-integer)
32+
- [Array of Text](#array-of-text)
3233
- [Column Options](#column-options)
3334
- [Compression](#compression)
3435
- [Views](#views)
@@ -159,6 +160,14 @@ The array of integer data type can be used to store a list of integers.
159160
$table->intArray(string $column);
160161
```
161162

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+
162171
### Column Options
163172

164173
#### Compression

src/Schema/Postgres/Blueprint.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ public function uuidArray(string $column): ColumnDefinition
137137
return $this->addColumn('uuidArray', $column);
138138
}
139139

140+
/**
141+
* Create a new text[] column
142+
*/
143+
public function textArray(string $column): ColumnDefinition
144+
{
145+
return $this->addColumn('textArray', $column);
146+
}
147+
140148
/**
141149
* Create a new int[] column
142150
*

src/Schema/Postgres/Grammar/GrammarTypes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Php\Support\Laravel\Database\Schema\Postgres\Types\IntArrayType;
1212
use Php\Support\Laravel\Database\Schema\Postgres\Types\IpNetworkType;
1313
use Php\Support\Laravel\Database\Schema\Postgres\Types\NumericType;
14+
use Php\Support\Laravel\Database\Schema\Postgres\Types\TextArrayType;
1415
use Php\Support\Laravel\Database\Schema\Postgres\Types\TsRangeType;
1516
use Php\Support\Laravel\Database\Schema\Postgres\Types\UuidArrayType;
1617
use Php\Support\Laravel\Database\Schema\Postgres\Types\XmlType;
@@ -48,6 +49,11 @@ protected function typeUuidArray(ColumnDefinition $column): string
4849
return UuidArrayType::TYPE_NAME;
4950
}
5051

52+
protected function typeTextArray(ColumnDefinition $column): string
53+
{
54+
return TextArrayType::TYPE_NAME;
55+
}
56+
5157
protected function typeIntArray(ColumnDefinition $column): string
5258
{
5359
return IntArrayType::TYPE_NAME;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

0 commit comments

Comments
 (0)