NAME
DBIx::QuickORM::STH - Synchronous statement-handle wrapper.
DESCRIPTION
Wraps a live DBI statement handle and its result, implementing the statement-handle iteration contract (see DBIx::QuickORM::Role::STH): fetch a row factory, pull rows one at a time, and finalize when exhausted. The synchronous base class treats results as immediately available; the async and fork subclasses defer them.
When only_one is set, fetching a second row is an error. When no_rows is set the statement yields no rows. An optional on_ready callback builds the per-row fetch coderef once the result is available.
SYNOPSIS
my $sth = DBIx::QuickORM::STH->new(
connection => $connection,
dbh => $dbh,
sth => $dbi_sth,
sql => $sql,
source => $source,
result => $result,
);
while (my $row_hr = $sth->next) { ... }
ATTRIBUTES
- connection
-
The owning connection.
- dbh
-
The
DBIdatabase handle. - sth
-
The
DBIstatement handle. - sql
-
The SQL string that was executed.
- source
-
The source the rows belong to.
- only_one
-
When true, more than one row is an error.
- no_rows
-
When true, the statement is expected to yield no rows.
- dialect
-
The dialect, lazily taken from the connection.
- ready
-
True once results are available.
- result
-
The driver result for the executed statement.
- done
-
True once iteration has finished and the handle has been finalized.
- on_ready
-
Optional callback invoked with
($dbh, $sth, $result, $sql)to build the per-row fetch coderef.
PUBLIC METHODS
- $sth->clear
-
Release any resources tied to the statement. No-op in the synchronous base class; subclasses override it.
- $bool = $sth->ready
-
True once results are available; always true for the synchronous base class.
- $bool = $sth->got_result
-
True once a result has been obtained; always true for the synchronous base class.
- $dialect = $sth->dialect
-
The dialect, lazily taken from the connection.
- $bool = $sth->deferred_result
-
True when the result is fetched lazily rather than up front. False for the synchronous base class.
- $sth->init
-
Constructor hook that validates required attributes.
- $row_hr = $sth->next
-
Return the next row as a hashref, or undef once exhausted. With
only_oneset, a second row is an error.
PRIVATE METHODS
- $cb = $sth->_fetch
-
Build (and cache) the per-row fetch coderef, running
on_readyonce if set. - $row_hr = $sth->_next
-
Pull one row from the fetch coderef, finalizing the handle when exhausted.
- $sth->set_done
-
Finalize the handle: run any pending
on_ready, clear resources, and mark it done. Idempotent. - $sth->DESTROY
-
Finalize the handle on destruction if it has not already finished.
SOURCE
The source code repository for DBIx::QuickORM can be found at https://github.com/exodist/DBIx-QuickORM.
MAINTAINERS
AUTHORS
COPYRIGHT
Copyright Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.