| 1 | package DBIO::MySQL; | ||
| 2 | # ABSTRACT: MySQL-specific schema management for DBIO | ||
| 3 | 2 | our $VERSION = '0.900001'; | |
| 4 | |||
| 5 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 2 | ▶ | use base 'DBIO::Base'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | |||
| 11 | 0 | ▶ | sub connection { |
|
Subroutine
connection: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 12 | 0 | my ($self, @info) = @_; | |
| 13 | 0 | $self->storage_type('+DBIO::MySQL::Storage'); | |
| 14 | 0 | return $self->next::method(@info); | |
| 15 | } | ||
| 16 | |||
| 17 | 2 | 1; | |
| 18 | |||
| 19 | __END__ | ||
| 20 | |||
| 21 | =pod | ||
| 22 | |||
| 23 | =encoding UTF-8 | ||
| 24 | |||
| 25 | =head1 NAME | ||
| 26 | |||
| 27 | DBIO::MySQL - MySQL-specific schema management for DBIO | ||
| 28 | |||
| 29 | =head1 VERSION | ||
| 30 | |||
| 31 | version 0.900001 | ||
| 32 | |||
| 33 | =head1 SYNOPSIS | ||
| 34 | |||
| 35 | =head2 Schema class | ||
| 36 | |||
| 37 | package MyApp::Schema; | ||
| 38 | use DBIO Schema => -mysql; | ||
| 39 | |||
| 40 | The C<-mysql> shortcut pins C<+DBIO::MySQL::Storage> as the C<storage_type> | ||
| 41 | and is equivalent to the classic component form below. | ||
| 42 | |||
| 43 | package MyApp::Schema; | ||
| 44 | use DBIO 'Schema'; | ||
| 45 | __PACKAGE__->load_components('MySQL'); | ||
| 46 | |||
| 47 | =head2 Result classes | ||
| 48 | |||
| 49 | package MyApp::Schema::Result::Artist; | ||
| 50 | use DBIO; | ||
| 51 | |||
| 52 | __PACKAGE__->table('artist'); | ||
| 53 | __PACKAGE__->add_columns( | ||
| 54 | id => { data_type => 'integer', is_auto_increment => 1 }, | ||
| 55 | name => { data_type => 'varchar', size => 100 }, | ||
| 56 | ); | ||
| 57 | __PACKAGE__->set_primary_key('id'); | ||
| 58 | __PACKAGE__->has_many(cds => 'MyApp::Schema::Result::CD', 'artist_id'); | ||
| 59 | |||
| 60 | package MyApp::Schema::Result::CD; | ||
| 61 | use DBIO; | ||
| 62 | |||
| 63 | __PACKAGE__->table('cd'); | ||
| 64 | __PACKAGE__->add_columns( | ||
| 65 | id => { data_type => 'integer', is_auto_increment => 1 }, | ||
| 66 | artist_id => { data_type => 'integer' }, | ||
| 67 | title => { data_type => 'varchar', size => 200 }, | ||
| 68 | ); | ||
| 69 | __PACKAGE__->set_primary_key('id'); | ||
| 70 | __PACKAGE__->belongs_to(artist => 'MyApp::Schema::Result::Artist', 'artist_id'); | ||
| 71 | |||
| 72 | =head2 Connecting | ||
| 73 | |||
| 74 | my $schema = MyApp::Schema->connect($dsn, $user, $pass); | ||
| 75 | $schema->deploy; | ||
| 76 | |||
| 77 | my $artist = $schema->resultset('Artist')->create({ name => 'Sonic Youth' }); | ||
| 78 | my @cds = $artist->cds->all; | ||
| 79 | |||
| 80 | For MariaDB use C<MySQL::MariaDB> instead: | ||
| 81 | |||
| 82 | __PACKAGE__->load_components('MySQL::MariaDB'); | ||
| 83 | |||
| 84 | The classic C<use base> form is still supported: | ||
| 85 | |||
| 86 | package MyApp::Schema; | ||
| 87 | use base 'DBIO::Schema'; | ||
| 88 | __PACKAGE__->load_components('MySQL'); | ||
| 89 | |||
| 90 | =head1 DESCRIPTION | ||
| 91 | |||
| 92 | L<DBIO::MySQL> is the MySQL driver component for DBIO. | ||
| 93 | |||
| 94 | When this component is loaded into a schema class, C<connection()> sets | ||
| 95 | L<DBIO::Schema/storage_type> to C<+DBIO::MySQL::Storage>, which enables | ||
| 96 | MySQL-specific storage behavior automatically. | ||
| 97 | |||
| 98 | For MariaDB-specific behavior, see L<DBIO::MySQL::MariaDB> and | ||
| 99 | L<DBIO::MySQL::Storage::MariaDB>. | ||
| 100 | |||
| 101 | =head1 METHODS | ||
| 102 | |||
| 103 | =head2 connection | ||
| 104 | |||
| 105 | Overrides L<DBIO/connection> to force C<+DBIO::MySQL::Storage> as | ||
| 106 | C<storage_type>. | ||
| 107 | |||
| 108 | =head1 MIGRATION NOTES | ||
| 109 | |||
| 110 | MySQL storage and SQLMaker classes were split out of the historical | ||
| 111 | DBIx::Class monolithic distribution: | ||
| 112 | |||
| 113 | =over 4 | ||
| 114 | |||
| 115 | =item * | ||
| 116 | |||
| 117 | Old: C<DBIx::Class::Storage::DBI::mysql> | ||
| 118 | |||
| 119 | =item * | ||
| 120 | |||
| 121 | New: C<DBIO::MySQL::Storage> | ||
| 122 | |||
| 123 | =item * | ||
| 124 | |||
| 125 | Old: C<DBIx::Class::Storage::DBI::MariaDB> | ||
| 126 | |||
| 127 | =item * | ||
| 128 | |||
| 129 | New: C<DBIO::MySQL::Storage::MariaDB> | ||
| 130 | |||
| 131 | =item * | ||
| 132 | |||
| 133 | Old: C<DBIx::Class::SQLMaker::MySQL> | ||
| 134 | |||
| 135 | =item * | ||
| 136 | |||
| 137 | New: C<DBIO::MySQL::SQLMaker> | ||
| 138 | |||
| 139 | =back | ||
| 140 | |||
| 141 | If C<DBIO-MySQL> is installed, core L<DBIO::Storage::DBI> can autodetect MySQL | ||
| 142 | DSNs and load the new storage class via the driver registry. | ||
| 143 | |||
| 144 | =head1 TESTING | ||
| 145 | |||
| 146 | Integration tests in this distribution use: | ||
| 147 | |||
| 148 | DBIO_TEST_MYSQL_DSN | ||
| 149 | DBIO_TEST_MYSQL_USER | ||
| 150 | DBIO_TEST_MYSQL_PASS | ||
| 151 | |||
| 152 | SQLMaker-focused tests can run offline via L<DBIO::Test> with: | ||
| 153 | |||
| 154 | storage_type => 'DBIO::MySQL::Storage' | ||
| 155 | |||
| 156 | Replicated-path tests can reuse the same harness with: | ||
| 157 | |||
| 158 | replicated => 1, | ||
| 159 | storage_type => 'DBIO::MySQL::Storage' | ||
| 160 | |||
| 161 | =head1 AUTHOR | ||
| 162 | |||
| 163 | DBIO & DBIx::Class Authors | ||
| 164 | |||
| 165 | =head1 COPYRIGHT AND LICENSE | ||
| 166 | |||
| 167 | Copyright (C) 2026 DBIO Authors | ||
| 168 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||
| 169 | Based on DBIx::Class, heavily modified. | ||
| 170 | |||
| 171 | This is free software; you can redistribute it and/or modify it under | ||
| 172 | the same terms as the Perl 5 programming language system itself. | ||
| 173 | |||
| 174 | =cut | ||