| 1 | package DBIO::MySQL::Result; | ||||||||||
| 2 | # ABSTRACT: MySQL/MariaDB-specific Result component for DBIO | ||||||||||
| 3 | |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use base 'DBIO::Core'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | __PACKAGE__->mk_classdata('_mysql_indexes' => {}); | |||||||||
| 10 | 2 | __PACKAGE__->mk_classdata('_mysql_engine'); | |||||||||
| 11 | 2 | __PACKAGE__->mk_classdata('_mysql_charset'); | |||||||||
| 12 | 2 | __PACKAGE__->mk_classdata('_mysql_collate'); | |||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | sub mysql_engine { | ||||||||
|
Subroutine
mysql_engine: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 17 | 2 | my ($class, $v) = @_; | |||||||||
| 18 | 2 | ▶ | $class->_mysql_engine($v) if defined $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 2 | return $class->_mysql_engine; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | sub mysql_charset { | ||||||||
|
Subroutine
mysql_charset: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 24 | 0 | my ($class, $v) = @_; | |||||||||
| 25 | 0 | ▶ | $class->_mysql_charset($v) if defined $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | return $class->_mysql_charset; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | sub mysql_collate { | ||||||||
|
Subroutine
mysql_collate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 31 | 0 | my ($class, $v) = @_; | |||||||||
| 32 | 0 | ▶ | $class->_mysql_collate($v) if defined $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | return $class->_mysql_collate; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | 1 | ▶ | sub mysql_index { | ||||||||
|
Subroutine
mysql_index: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 38 | 1 | my ($class, $name, $def) = @_; | |||||||||
| 39 | 1 | ▶ | if ($def) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 1 | my $indexes = { %{ $class->_mysql_indexes } }; | |||||||||
| 41 | 1 | $indexes->{$name} = $def; | |||||||||
| 42 | 1 | $class->_mysql_indexes($indexes); | |||||||||
| 43 | } | ||||||||||
| 44 | 1 | return $class->_mysql_indexes->{$name}; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | 1 | ▶ | sub mysql_indexes { | ||||||||
|
Subroutine
mysql_indexes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 49 | 1 | my ($class) = @_; | |||||||||
| 50 | 1 | return { %{ $class->_mysql_indexes } }; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | 2 | 1; | |||||||||
| 55 | |||||||||||
| 56 | __END__ | ||||||||||
| 57 | |||||||||||
| 58 | =pod | ||||||||||
| 59 | |||||||||||
| 60 | =encoding UTF-8 | ||||||||||
| 61 | |||||||||||
| 62 | =head1 NAME | ||||||||||
| 63 | |||||||||||
| 64 | DBIO::MySQL::Result - MySQL/MariaDB-specific Result component for DBIO | ||||||||||
| 65 | |||||||||||
| 66 | =head1 VERSION | ||||||||||
| 67 | |||||||||||
| 68 | version 0.900001 | ||||||||||
| 69 | |||||||||||
| 70 | =head1 DESCRIPTION | ||||||||||
| 71 | |||||||||||
| 72 | C<DBIO::MySQL::Result> is a DBIO Result component that adds | ||||||||||
| 73 | MySQL/MariaDB-native metadata to a result class: the table engine, | ||||||||||
| 74 | character set, collation, and custom indexes. It is the counterpart to | ||||||||||
| 75 | L<DBIO::PostgreSQL::Result> / L<DBIO::SQLite::Result> and is read by | ||||||||||
| 76 | L<DBIO::MySQL::DDL> when generating install DDL. | ||||||||||
| 77 | |||||||||||
| 78 | Load it with: | ||||||||||
| 79 | |||||||||||
| 80 | package MyApp::DB::Result::User; | ||||||||||
| 81 | use base 'DBIO::Core'; | ||||||||||
| 82 | __PACKAGE__->load_components('MySQL::Result'); | ||||||||||
| 83 | |||||||||||
| 84 | __PACKAGE__->table('users'); | ||||||||||
| 85 | __PACKAGE__->mysql_engine('InnoDB'); | ||||||||||
| 86 | __PACKAGE__->mysql_charset('utf8mb4'); | ||||||||||
| 87 | __PACKAGE__->mysql_collate('utf8mb4_unicode_ci'); | ||||||||||
| 88 | |||||||||||
| 89 | __PACKAGE__->mysql_index('idx_users_name' => { | ||||||||||
| 90 | columns => ['name'], | ||||||||||
| 91 | }); | ||||||||||
| 92 | |||||||||||
| 93 | __PACKAGE__->mysql_index('idx_users_fulltext' => { | ||||||||||
| 94 | using => 'FULLTEXT', | ||||||||||
| 95 | columns => ['bio'], | ||||||||||
| 96 | }); | ||||||||||
| 97 | |||||||||||
| 98 | =head1 METHODS | ||||||||||
| 99 | |||||||||||
| 100 | =head2 mysql_engine | ||||||||||
| 101 | |||||||||||
| 102 | __PACKAGE__->mysql_engine('InnoDB'); | ||||||||||
| 103 | my $e = $class->mysql_engine; | ||||||||||
| 104 | |||||||||||
| 105 | Get or set the MySQL storage engine for this result class's table. | ||||||||||
| 106 | Defaults to C<InnoDB> in the generated DDL when unset. | ||||||||||
| 107 | |||||||||||
| 108 | =head2 mysql_charset | ||||||||||
| 109 | |||||||||||
| 110 | __PACKAGE__->mysql_charset('utf8mb4'); | ||||||||||
| 111 | my $c = $class->mysql_charset; | ||||||||||
| 112 | |||||||||||
| 113 | Get or set the default character set for this table. Defaults to | ||||||||||
| 114 | C<utf8mb4> in generated DDL when unset. | ||||||||||
| 115 | |||||||||||
| 116 | =head2 mysql_collate | ||||||||||
| 117 | |||||||||||
| 118 | __PACKAGE__->mysql_collate('utf8mb4_unicode_ci'); | ||||||||||
| 119 | my $c = $class->mysql_collate; | ||||||||||
| 120 | |||||||||||
| 121 | Get or set the default collation for this table. Defaults to | ||||||||||
| 122 | C<utf8mb4_unicode_ci> in generated DDL when unset. | ||||||||||
| 123 | |||||||||||
| 124 | =head2 mysql_index | ||||||||||
| 125 | |||||||||||
| 126 | __PACKAGE__->mysql_index('idx_users_name' => { | ||||||||||
| 127 | columns => ['name'], | ||||||||||
| 128 | }); | ||||||||||
| 129 | __PACKAGE__->mysql_index('idx_users_fulltext' => { | ||||||||||
| 130 | using => 'FULLTEXT', | ||||||||||
| 131 | columns => ['bio'], | ||||||||||
| 132 | }); | ||||||||||
| 133 | |||||||||||
| 134 | Get or set the definition for a named MySQL index. The definition | ||||||||||
| 135 | hashref accepts: | ||||||||||
| 136 | |||||||||||
| 137 | =over 4 | ||||||||||
| 138 | |||||||||||
| 139 | =item C<columns> - ArrayRef of column names | ||||||||||
| 140 | |||||||||||
| 141 | =item C<unique> - set to true for a UNIQUE index | ||||||||||
| 142 | |||||||||||
| 143 | =item C<using> - C<BTREE>, C<HASH>, C<FULLTEXT>, or C<SPATIAL> | ||||||||||
| 144 | |||||||||||
| 145 | =back | ||||||||||
| 146 | |||||||||||
| 147 | =head2 mysql_indexes | ||||||||||
| 148 | |||||||||||
| 149 | my $all = $class->mysql_indexes; | ||||||||||
| 150 | |||||||||||
| 151 | Returns a copy of all index definitions registered on this result class. | ||||||||||
| 152 | |||||||||||
| 153 | =seealso | ||||||||||
| 154 | |||||||||||
| 155 | =over 4 | ||||||||||
| 156 | |||||||||||
| 157 | =item * L<DBIO::MySQL::DDL> - consumes C<mysql_indexes>, C<mysql_engine>, C<mysql_charset>, C<mysql_collate> | ||||||||||
| 158 | |||||||||||
| 159 | =item * L<DBIO::PostgreSQL::Result> - the PostgreSQL counterpart | ||||||||||
| 160 | |||||||||||
| 161 | =back | ||||||||||
| 162 | |||||||||||
| 163 | =head1 AUTHOR | ||||||||||
| 164 | |||||||||||
| 165 | DBIO & DBIx::Class Authors | ||||||||||
| 166 | |||||||||||
| 167 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 168 | |||||||||||
| 169 | Copyright (C) 2026 DBIO Authors | ||||||||||
| 170 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||
| 171 | Based on DBIx::Class, heavily modified. | ||||||||||
| 172 | |||||||||||
| 173 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 174 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 175 | |||||||||||
| 176 | =cut | ||||||||||