Mojo::PgX::Cursor - Cursor Extension for Mojo::Pg
my $pg = Mojo::PgX::Cursor->new('postgresql://postgres@/test');
my $results = $pg->db->cursor('select * from some_big_table');
while (my $next = $results->hash) {
say $next->{name};
}
DBD::Pg fetches all rows when a statement is executed whereas other drivers
usually fetch rows using the fetch*
methods. Mojo::PgX::Cursor is an
extension to work around this issue using PostgreSQL cursors while providing a
Mojo::Pg-style API for iteratoring over the results; see
Mojo::PgX::Cursor::Results for details.
This subclass overrides Mojo::Pg's implementation in order to subclass the resulting Mojo::Pg::Database object into a Mojo::PgX::Cursor::Database.
This module will follow Semantic Versioning 2.0.0. Once the API feels reasonable I'll release v1.0.0 which would correspond to 1.000000 according to version,
version->declare(q(v1.0.0))->numify # 1.000000
version->parse(q(1.000000))->normal # v1.0.0
require Mojo::Pg;
require Mojo::PgX::Cursor;
use Mojo::Util 'monkey_patch';
monkey_patch 'Mojo::Pg::Database', 'cursor', \&Mojo::PgX::Cursor::Database::cursor;
Just because you can doesn't mean you should but if you want you can
monkey_patch
Mojo::Pg::Database rather than swapping out your
construction of Mojo::Pg objects with the Mojo::PgX::Cursor subclass.
This module would be unnecessary if DBD::Pg did not fetch all rows during
execute
and since libpq
supports that it would be much better to fix
fetch*
than to implement this. However, I am not able to do so at this
time.
If you would like to submit bug reports, feature requests, questions, etc. you should create an issue on the GitHub Issue Tracker for this module.
Copyright (C) Nathaniel Nutter.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Nathaniel Nutter nnutter@cpan.org
DBD::Pg, Mojo::Pg, Mojo::PgX::Cursor::Cursor, Mojo::PgX::Cursor::Database, Mojo::PgX::Cursor::Results