Norma::ORM::Collection - Queries and results with metadata from classes consuming the Norma::ORM::Mappable role
my $uk_customers = Norma::ORM::Collection->new( class => 'MyApp::Customer', where => { country => 'UK' }, ); for my $customer ($uk_customers->items) { ... }
Queries the database and returns a collection which contains an array of instantiated objects, along with other metadata. We'll take the following parameters:
Specify join clauses as hashrefs, table names (or derived tables / sub queries if you like) pointing to column associations.
join => [ customer_notes => 'customer_notes.customer_id = customers.id', '(select customer_id, min(order_date) first_order_date from orders group by customer_id) first_order_dates' => 'first_order_dates.customer_id = customers.id' ]
Criteria for the "where" clause may be specified in a number of ways. For simple lookups, key / value pairs will suffice. To find customers in London, you might try:
where => { city => 'London', country => 'UK', }
For comparisons other than equality, sepcify the sql comparison in the key itself. To find customers in Eastern Central London by postcode, you might try:
where => { 'postal_code like' => 'EC%', country => 'UK' }
If you need more flexibility, you can pass in your own where clauses along-with:
where => [ q{ postal_code between 'EC2' and 'EC4' }, { country => 'UK' }, ]
Outside of custom where clauses, values will be quoted by DBI::quote.
Order the query according to this clause, if specified
Return this many items
Return items starting at this offset
Array of objects where each one is an instance of the given $class
The number of rows that matched this query
The actual SQL query that was run
The name of the class of the objects returned via items
Norma, Norma::ORM::Mappable
David Chester <davidchester@gmx.net>
This software is copyright (c) 2010-2011 by David Chester.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Norma, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Norma
CPAN shell
perl -MCPAN -e shell install Norma
For more information on module installation, please visit the detailed CPAN module installation guide.