| 1 | package DBIO::GraphQL::ScalarMap; | ||||||||||||
| 2 | # ABSTRACT: Map DBIO column data_types to GraphQL scalars | ||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 8 | ▶ | use GraphQL::Type::Scalar qw($Int $String $Float $Boolean); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 8 | ▶ | use Exporter 'import'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 8 | our @EXPORT_OK = qw( for_column ); | |||||||||||
| 10 | |||||||||||||
| 11 | # Resolution order matters: | ||||||||||||
| 12 | # 1. Boolean: must come before Int because tinyint(1) is the MySQL idiom | ||||||||||||
| 13 | # 2. Float : decimal/numeric before the int catch-all | ||||||||||||
| 14 | # 3. Int : all integer family types | ||||||||||||
| 15 | # 4. String : safe fallback for anything unrecognised | ||||||||||||
| 16 | 704 | ▶ | sub for_column { | ||||||||||
|
Subroutine
for_column: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||
| 17 | 704 | my ($source, $col) = @_; | |||||||||||
| 18 | 704 | my $info = $source->column_info($col); | |||||||||||
| 19 | 704 | ▶ | 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"}
| |||||||||||||
| 20 | |||||||||||||
| 21 | 704 | ▶ | return $Boolean if $data_type =~ /(?:\b(?:bool(?:ean)?)|tinyint\(1\))(?=\s|\z)/i; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | 592 | ▶ | return $Float if $data_type =~ /\b(?:float|double(?:\s+precision)?|real|money|decimal|numeric)\b/i; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | 474 | ▶ | return $Int if $data_type =~ /\b(?:int(?:eger)?|bigint|smallint|tinyint|mediumint|serial)\b/i; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | 211 | return $String; | |||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | 8 | 1; | |||||||||||
| 28 | |||||||||||||
| 29 | __END__ | ||||||||||||
| 30 | |||||||||||||
| 31 | =pod | ||||||||||||
| 32 | |||||||||||||
| 33 | =encoding UTF-8 | ||||||||||||
| 34 | |||||||||||||
| 35 | =head1 NAME | ||||||||||||
| 36 | |||||||||||||
| 37 | DBIO::GraphQL::ScalarMap - Map DBIO column data_types to GraphQL scalars | ||||||||||||
| 38 | |||||||||||||
| 39 | =head1 VERSION | ||||||||||||
| 40 | |||||||||||||
| 41 | version 0.900001 | ||||||||||||
| 42 | |||||||||||||
| 43 | =head1 AUTHOR | ||||||||||||
| 44 | |||||||||||||
| 45 | DBIO Authors | ||||||||||||
| 46 | |||||||||||||
| 47 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 48 | |||||||||||||
| 49 | Copyright (C) 2026 DBIO Authors | ||||||||||||
| 50 | |||||||||||||
| 51 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 52 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 53 | |||||||||||||
| 54 | =cut | ||||||||||||