NAME

DBIO::MySQL::Storage - MySQL storage layer for DBIO

VERSION

version 0.900000

SYNOPSIS

package MyApp::Schema;
use base 'DBIO::Schema';
__PACKAGE__->load_components('MySQL');

# Optionally enable strict mode on connect
my $schema = MyApp::Schema->connect(
  $dsn, $user, $pass,
  { on_connect_call => 'set_strict_mode' },
);

DESCRIPTION

MySQL storage backend for DBIO. Extends DBIO::Storage::DBI with MySQL-specific behavior:

  • Uses backtick quoting and LimitXY pagination dialect.

  • Routes SQL generation through DBIO::MySQL::SQLMaker.

  • Routes SQL generation through DBIO::MySQL::SQLMaker, which automatically wraps UPDATE and DELETE statements that reference the modification target in a subquery.

  • Disables mysql_auto_reconnect by default to prevent silent transaction loss.

This class is auto-registered for the mysql DBI driver and is set as the active storage class when "connection" in DBIO::MySQL is called.

METHODS

with_deferred_fk_checks

$storage->with_deferred_fk_checks(sub { ... });

Executes the given coderef with FOREIGN_KEY_CHECKS disabled for the duration of the call. Useful when loading data with circular foreign key dependencies.

connect_call_set_strict_mode

my $schema = MyApp::Schema->connect(
  $dsn, $user, $pass,
  { on_connect_call => 'set_strict_mode' },
);

Connection callback that enables ANSI, TRADITIONAL, and ONLY_FULL_GROUP_BY SQL modes and disables SQL_AUTO_IS_NULL. Pass set_strict_mode as an on_connect_call option to activate it.

deploy_defaults

MySQL has no transactional DDL and no IF NOT EXISTS on all statement types. Returns add_drop_table => 1 so that DBIO::Test can safely re-deploy the same schema in a test sequence without hitting table already exists errors.

deploy_setup

Strips NO_ZERO_DATE and NO_ZERO_IN_DATE from the session sql_mode before deploying a schema during tests. MySQL 8 strict mode rejects 0000-00-00 which the test suite uses to verify datetime_undef_if_invalid behaviour.

deployment_statements

Overrides the base implementation to automatically pass mysql_version to the SQL::Translator producer args when deploying a schema, so that generated DDL is compatible with the connected server version.

is_replicating

Returns true if the connected MySQL replica is currently replicating from its master (both IO and SQL threads running). Intended for use with DBIO::Replicated::Storage.

_replication_status_row

my $row = $storage->_replication_status_row;

Returns the SHOW SLAVE STATUS / SHOW REPLICA STATUS row as a hashref, or undef when the connected server is not a replica. The default implementation queries the legacy SHOW SLAVE STATUS statement; the MariaDB subclass tries the modern SHOW REPLICA STATUS first and falls back to the legacy statement.

This is the engine seam: anything that needs to read replication state should go through here instead of issuing SHOW ... STATUS itself.

lag_behind_master

Returns the number of seconds the replica is behind the master, as reported by SHOW SLAVE STATUS. Returns undef if replication status is unavailable.

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 279:

Unknown directive: =seealso