NAME
DBIx::Squirrel::Stages::Rows - stages reshaping rows: pluck and as_hash
SYNOPSIS
use DBIx::Squirrel::Stages::Rows; # pluck and as_hash
# Each artist's name
my @names = $dbh->iterate('SELECT id, name FROM artist', pluck('name'))->all;
# Each row as a hash, as fetchrow_hashref gives it
my @rows = $dbh->iterate('SELECT id, name FROM artist', as_hash)->all;
DESCRIPTION
Stages that reshape rows, whatever shape they were fetched in: as arrays, as hashes (with the ekorn_slice attribute), or as row objects (from results). Each finds what it needs from the statement's column names, once on each run, in the context a statement gives the run: in an iterator's own stages, or in a chain made with |, or a pipeline of yours, reading one. So a stage can be given to statements whose columns differ.
The columns are the statement's, not the row's. After a stage that reshapes rows, pluck by a name for an array row, or by a position, picks the wrong field, and says nothing. Use "as_hash" first, and pluck by name then reads each hash's own keys.
FUNCTIONS
Both are exported by default, and with :all.
pluck
pluck($name)
pluck($position)
Gives one column of each row, by its name, in any case, or by its position, from 0, as a row object's get_column does. A name for an array row, or a position for a hash row, is found from the column names. So it needs to be in a run reading a statement. A column the row hasn't got croaks.
as_hash
as_hash
Makes each row a hash, keyed by the column names as fetchrow_hashref would key them, following FetchHashKeyName. So it gives what plain DBI does. An array row, or a row object, is made into a new hash. A hash row is passed on unchanged. As with fetchrow_hashref, of two columns with the same name, the hash has one. It needs to be in a run reading a statement, for the column names.
DIAGNOSTICS
- Expected a column, by name or position
-
pluckwas given no column, or an empty name. - Expected a column of the row (%s)
-
A row hasn't got the column
pluckwas given. - Expected a statement to read, for the column names
-
as_hash, orpluckwith a name for an array row or a position for a hash row, ran where no statement was being read, such as in a pipeline called with values. So the column names aren't known. - Expected a row: an array, a hash or a row object
-
A stage was given a value that isn't a row.
SEE ALSO
DBIx::Squirrel, DBIx::Squirrel::Iterator, DBIx::Squirrel::Result, DBIx::Squirrel::Context
AUTHOR
Iain Campbell <cpanic@cpan.org>
LICENSE
Copyright (c) 2024-2026 by Iain Campbell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.