Skip to content

Commit

Permalink
CT-1526 - extract column info into standalone static method
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtabiberle committed Aug 7, 2024
1 parent 489cfcc commit d70f4a8
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public static function createFromDB(array $dbResponse): SnowflakeColumn
$default = $dbResponse['default'];
$length = null;

$matches = [];
if (preg_match('/^(?<type>\w+)\((?<length>[a-zA-Z0-9, ]+)\)$/ui', $dbResponse['type'], $matches)) {
$type = $matches['type'];
$length = $matches['length'];
$info = self::extractTypeAndLengthFromDB($dbResponse['type']);
if ($info !== null) {
$type = $info['type'];
$length = $info['length'];
}

return new self($dbResponse['name'], new Snowflake(
Expand All @@ -79,6 +79,22 @@ public static function createFromDB(array $dbResponse): SnowflakeColumn
));
}

/**
* @return array{type: string, length: string}|null
*/
public static function extractTypeAndLengthFromDB(string $dbType): ?array
{
$matches = [];
if (preg_match('/^(?<type>\w+)\((?<length>[a-zA-Z0-9, ]+)\).*$/ui', $dbType, $matches)) {
$type = $matches['type'];
$length = $matches['length'];

return ['type' => $type, 'length' => $length];
}

return null;
}

public static function createTimestampColumn(string $columnName = self::TIMESTAMP_COLUMN_NAME): SnowflakeColumn
{
return new self(
Expand Down

0 comments on commit d70f4a8

Please sign in to comment.