ActiveRecord-Simple

 view release on metacpan or  search on metacpan

lib/ActiveRecord/Simple/Find.pm  view on Meta::CPAN

=head2 offset

SET "OFFSET" to the query:

    # SELECT * FROM log LIMIT 100 OFFSET 99;
    my @logs = Log->find->limit(100)->offset(99);

=head2 group_by

Set "GROUP BY":

    my @logs = Log->find->group_by('level');

=head2 with 

Set "LEFT JOIN" command to the query:

    # SELECT l.*, s.* FROM logs l LEFT JOIN sites s ON s.id = l.site_id
    my @logs_and_sites = Log->find->with('sites');
    print $_->site->name, ": ", $_->mesage for @logs_and_sites;

=head2 left_join

The same as "with" method

=head2 uplod

Fetch object from database and load into ActiveRecord::Simple::Find object:

    my $logs = Log->find({ level => ['error', 'fatal'] });
    $logs->order_by('level')->desc;
    $logs->limit(100);
    $logs->upload;

    print $_->message for @$logs;

=head2 to_sql

Show SQL-query that genereted by ActiveRecord::Simple::Find class:

    my $finder = Log->frind->only('message')->order_by('level')->desc->limit(100);
    print $finder->to_sql; # prints: SELECT message FROM log ORDER BY level DESC LIMIT 100;


=head1 EXAMPLES

    # SELECT * FROM pizza WHERE name = 'pepperoni';
    Pizza->find({ name => 'pepperoni' });

    # SELECT first_name, last_name FORM customer WHERE age > 21 ORDER BY id DESC LIMIT 100;
    Customer->find('age > ?', 21)->only('first_name', 'last_name')->order_by('id')->desc->limit(100);

    # SELECT p.filename, p.id, pp.* FROM photo p LEFT JOIN person pp ON p.person_id = pp.id WHERE p.size = '1020x768';
    Photo->find({ size => '1020x768' })->with('person')->only('filename', 'id');

    # SELECT t.* FROM topping_pizza tp LEFT JOIN topping t ON t.id = tp.topping_id  WHERE tp.pizza_id = <$val>;
    Pizza->get(<$val>)->toppings();

=head1 AUTHOR

shootnix, C<< <shootnix at cpan.org> >>

=head1 BUGS

Please report any bugs or feature requests to C<shootnix@cpan.org>, or through
the github: https://github.com/shootnix/activerecord-simple/issues

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc ActiveRecord::Simple


You can also look for information at:

=over 1

=item * Github wiki:

L<https://github.com/shootnix/activerecord-simple/wiki>

=back

=head1 ACKNOWLEDGEMENTS


=head1 LICENSE AND COPYRIGHT

Copyright 2013-2018 shootnix.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

=cut



( run in 1.259 second using v1.01-cache-2.11-cpan-df04353d9ac )