Mojo::Pg::Database::Role::PgPromiseClass - db query promises use Pg's promise_class
version 0.001
# extend $pg to allow messing with promise_class $pg = Mojo::Pg->new(...)->with_roles('+PromiseClass'); # but we also want funky database with spoons and llamas $pg->database_class( Mojo::Pg::Database->with_roles('+PgPromiseClass','+Spoons','+Llamas',...) ); # declare additional promise roles on $pg $pg->promise_roles('+Repeat'); # and they will show up on every subsequent query_p $pg->db->query_p('SELECT * FROM wombats')->repeat(sub{...});
Mojo::Pg::Database::Role::PgPromiseClass is a role to be applied to Mojo::Pg::Database-derived objects that has them refer to their parent Mojo::Pg instance to determine the class used for promises returned by query_p et al, for situations where you want that class to be different from Mojo::Promise.
You should only be needing to explicitly add this role in cases where you are customizing both the promise class and the database class. The default database class already includes this role when the Pg wrapper has been extended via Mojo::Pg::Role::PromiseClass.
Note that since nearly all Mojo::Promise methods use clone to create new instances, roles assigned to promises in this way will generally propagate down method chains.
This role adds no additional attributes.
This role adds no additional methods.
query_p and all methods that are derived from it (delete_p, insert_p, select_p, and update_p) are all modified to return promises of the specified class.
Mojo::Pg::Database, Mojo::Promise, Mojolicious, Mojolicious::Guides, https://mojolicious.org.
Roger Crew <wrog@cpan.org>
This software is copyright (c) 2019 by Roger Crew.
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 Mojo::Pg::Role::PromiseClass, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Pg::Role::PromiseClass
CPAN shell
perl -MCPAN -e shell install Mojo::Pg::Role::PromiseClass
For more information on module installation, please visit the detailed CPAN module installation guide.