File Coverage

blib/lib/DBIx/Result/Convert/JSONSchema/Type/MySQL.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             package DBIx::Result::Convert::JSONSchema::Type::MySQL;
2              
3             =head1 NAME
4              
5             DBIx::Result::Convert::JSONSchema::Type::MySQL - Mapping of MySQL field type to JSON property type
6              
7             =head1 VERSION
8              
9             0.01
10              
11             =head1 SYNOPSIS
12              
13             use DBIx::Result::Convert::JSONSchema::Type::MySQL;
14             my $type_map = DBIx::Result::Convert::JSONSchema::Type::MySQL->get_type_map;
15              
16             =head1 DESCRIPTION
17              
18             This module defines mapping between DBIx MySQL field types to JSON schema property types.
19              
20             =cut
21              
22 4     4   2998 use strict;
  4         23  
  4         157  
23 4     4   25 use warnings;
  4         15  
  4         165  
24              
25             our $VERSION = '0.01';
26              
27 4     4   514 use Readonly;
  4         3925  
  4         817  
28              
29              
30             Readonly my %TYPE_MAP => (
31             string => [
32             qw/ char varchar binary varbinary blob text mediumtext tinytext /,
33             qw/ date datetime timestamp time year /
34             ],
35             enum => [ qw/ enum set / ],
36             integer => [ qw/ integer smallint tinyint mediumint bigint bit / ],
37             number => [ qw/ decimal float double /, 'double precision' ],
38             object => [ qw/ json / ],
39             );
40              
41             =head2 C
42              
43             Return mapping of DBIx::Class:Result field name => JSON Schema field name.
44              
45             # { decimal => 'number', time => 'string', ... }
46             my $map = DBIx::Result::Convert::Type::MySQL->get_type_map;
47              
48             =cut
49              
50             sub get_type_map {
51 5     5 1 260600 my ( $class ) = @_;
52              
53 5         30 my $mapped_fields;
54 5         36 foreach my $json_type ( keys %TYPE_MAP ) {
55 25         337 foreach my $dbix_type ( @{ $TYPE_MAP{ $json_type } } ) {
  25         101  
56 130         1325 $mapped_fields->{ $dbix_type } = $json_type;
57             }
58             }
59              
60 5         165 return $mapped_fields;
61             }
62              
63             =head1 AUTHOR
64              
65             malishew - C
66              
67             =head1 LICENSE
68              
69             This library is free software; you can redistribute it and/or modify it under
70             the same terms as Perl itself. If you would like to contribute documentation
71             or file a bug report then please raise an issue / pull request:
72              
73             https://github.com/Humanstate/p5-dbix-result-convert-jsonschema
74              
75             =cut
76              
77             1;