| 1 | package DBIO::GraphQL::ScalarMap; | ||||||||||||
| 2 | # ABSTRACT: Map DBIO column data_types to GraphQL scalars | ||||||||||||
| 3 | 15 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 15 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 15 | our $VERSION = '0.900007'; | |||||||||||
| 7 | |||||||||||||
| 8 | 15 | ▶ | use GraphQL::Type::Scalar qw($Int $String $Float $Boolean); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 15 | ▶ | use Exporter 'import'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 15 | our @EXPORT_OK = qw( for_column ); | |||||||||||
| 12 | |||||||||||||
| 13 | # Resolution order matters: | ||||||||||||
| 14 | # 1. Boolean: must come before Int because tinyint(1) is the MySQL idiom | ||||||||||||
| 15 | # 2. String : bigint/bigserial/decimal/numeric/money; GraphQL Int is 32-bit | ||||||||||||
| 16 | # signed and Float a double, so these would lose values | ||||||||||||
| 17 | # 3. Float : float/double/real | ||||||||||||
| 18 | # 4. Int : the 32-bit integer family | ||||||||||||
| 19 | # 5. String : safe fallback for anything unrecognised | ||||||||||||
| 20 | 2043 | ▶ | sub for_column { | ||||||||||
|
Subroutine
for_column: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 21 | 2043 | my ($source, $col) = @_; | |||||||||||
| 22 | 2043 | my $info = $source->column_info($col); | |||||||||||
| 23 | 2043 | ▶ | my $data_type = $info->{data_type} // ''; | ||||||||||
|
Condition100%2/2
$info->{"data_type"} // ""
MC/DC100%1/1
$info->{"data_type"} // ""
$info->{"data_type"}
Truth table100%2/2
A
A= $info->{"data_type"}
| |||||||||||||
| 24 | |||||||||||||
| 25 | 2043 | ▶ | return $Boolean if $data_type =~ /(?:\b(?:bool(?:ean)?)|tinyint\(1\))(?=\s|\z)/i; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 1854 | ▶ | return $String if $data_type =~ /\b(?:bigint|bigserial|money|decimal|numeric)\b/i; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 1748 | ▶ | return $Float if $data_type =~ /\b(?:float|double(?:\s+precision)?|real)\b/i; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 1644 | ▶ | return $Int if $data_type =~ /\b(?:int(?:eger)?|smallint|tinyint|mediumint|serial)\b/i; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 633 | return $String; | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | 15 | 1; | |||||||||||
| 33 | |||||||||||||
| 34 | __END__ | ||||||||||||