Skip to content

Commit 5c112b0

Browse files
Added support for JSON datatype (#360)
Co-authored-by: Markus Staab <[email protected]>
1 parent 3b1c984 commit 5c112b0

14 files changed

+657
-353
lines changed

.phpstan-dba-mysqli.cache

Lines changed: 0 additions & 208 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/QueryReflection/BasePdoQueryReflector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use staabm\PHPStanDba\TypeMapping\TypeMapper;
1717

1818
/**
19-
* @phpstan-type ColumnMeta array{name: string, table: string, native_type: string, len: int, flags: list<string>}
19+
* @phpstan-type ColumnMeta array{name: string, table: string, native_type: string, len: int, flags: list<string>, pdo_type: int}
2020
*/
2121
abstract class BasePdoQueryReflector
2222
{

src/QueryReflection/PdoQueryReflector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ protected function simulateQuery(string $queryString)
7171
throw new ShouldNotHappenException('Failed to get column meta for column index '.$columnIndex);
7272
}
7373

74+
/*
75+
* Native type may not be set, for example in case of JSON column.
76+
* @phpstan-ignore-next-line
77+
*/
78+
if (!isset($columnMeta['native_type'])) {
79+
$columnMeta['native_type'] = \PDO::PARAM_INT === $columnMeta['pdo_type'] ? 'INT' : 'STRING';
80+
}
81+
7482
$flags = $this->emulateFlags($columnMeta['native_type'], $columnMeta['table'], $columnMeta['name']);
7583
foreach ($flags as $flag) {
7684
$columnMeta['flags'][] = $flag;

src/TypeMapping/PgsqlTypeMapper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPStan\ShouldNotHappenException;
88
use PHPStan\Type\Accessory\AccessoryNumericStringType;
9+
use PHPStan\Type\BooleanType;
910
use PHPStan\Type\FloatType;
1011
use PHPStan\Type\IntegerType;
1112
use PHPStan\Type\IntersectionType;
@@ -73,10 +74,13 @@ public function mapToPHPStanType(string $type, array $flags, int $length): Type
7374
// fallbacks
7475
if (null === $phpstanType) {
7576
$phpstanType = match (strtoupper($type)) {
77+
'BOOL' => new BooleanType(),
7678
'BIT',
7779
'INT2',
7880
'INT4',
7981
'INT8' => new IntegerType(),
82+
'JSON',
83+
'JSONB',
8084
'DATE',
8185
'TEXT',
8286
'TIME',

0 commit comments

Comments
 (0)