DBIx-QuickORM

 view release on metacpan or  search on metacpan

lib/DBIx/QuickORM/Manual/Connections.pm  view on Meta::CPAN

L<DBIx::QuickORM::Manual::Async>.

=head1 AUTO-RETRY FOR TRANSIENT FAILURES

Network blips and dropped connections happen. C<auto_retry> runs a block,
retrying it if it throws, and reconnects in place between attempts when the
handle is no longer responding:

    my $result = $con->auto_retry(sub { ... });
    my $result = $con->auto_retry($count => sub { ... });

C<auto_retry> cannot be used inside a transaction (a half-applied transaction
cannot be safely retried). For the transactional case use C<auto_retry_txn>,
which wraps the retried block in a transaction for you. Both are documented in
detail in L<DBIx::QuickORM::Manual::Transactions>.

=head1 CONFIGURING THE CONNECTION

How the C<DBI> handle is actually built is defined by the
L<DBIx::QuickORM::DB> object behind the ORM. There are two ways to specify it.

=head2 Credentials

Provide the pieces and let the ORM call C<< DBI->connect >> for you:

=over 4

=item dsn

The C<DBI> DSN string. When omitted it is built from the dialect and the
connection coordinates (C<host>/C<port>/C<socket> and C<db_name>).

=item user

=item pass

Credentials passed through to C<< DBI->connect >>.

=item attributes

A hashref of C<DBI> attributes. Sensible defaults (C<RaiseError>,
C<PrintError>, C<AutoCommit>, C<AutoInactiveDestroy>) are filled in for you.

=item dbi_driver

The C<DBI> driver name associated with the database.

=back

=head2 A connect callback

Alternatively, supply a C<connect> coderef that returns a fresh C<DBI> handle.
When present it is used instead of the DSN-based path, giving you full control
over how the handle is opened (custom drivers, connection pools, extra setup,
and so on):

    connect => sub { DBI->connect($dsn, $user, $pass, \%attrs) },

Each new handle - whether for the first connection, a reconnect, or a forked
child - is produced the same way: via your callback if you provided one,
otherwise via C<< DBI->connect >> with the resolved DSN and credentials. See
L<DBIx::QuickORM::DB> for the full set of configuration attributes.

=head1 SEE ALSO

=over 4

=item L<DBIx::QuickORM::Connection>

The connection object itself: transactions, handles, async/aside/forked
queries, and the state operations backing the row cache.

=item L<DBIx::QuickORM::ORM>

The owner of the primary connection.

=item L<DBIx::QuickORM::DB>

The database connection definition.

=item L<DBIx::QuickORM::Manual::Transactions>

Transactions, savepoints, and automatic retry.

=item L<DBIx::QuickORM::Manual::Caching>

The per-connection row cache that reconnecting in place preserves and that
C<< $orm->reconnect >> discards.

=item L<DBIx::QuickORM::Manual::QuickStart>

The C<quick()> interface that hands back a ready connection.

=item L<DBIx::QuickORM::Manual>

The documentation hub.

=back

=head1 SOURCE

The source code repository for DBIx-QuickORM can be found at
L<https://github.com/exodist/DBIx-QuickORM/>.

=head1 MAINTAINERS

=over 4

=item Chad Granum E<lt>exodist@cpan.orgE<gt>

=back

=head1 AUTHORS

=over 4

=item Chad Granum E<lt>exodist@cpan.orgE<gt>

=back

=head1 COPYRIGHT



( run in 0.594 second using v1.01-cache-2.11-cpan-5b529ec07f3 )