NAME

Mojo::Pg::Database::Role::PgPromiseClass - db query promises use Pg's promise_class

VERSION

version 0.002

SYNOPSIS

  # 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{...});

DESCRIPTION

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.

ATTRIBUTES

This role adds no additional attributes.

METHODS

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.

SEE ALSO

Mojo::Pg::Database, Mojo::Promise, Mojolicious, Mojolicious::Guides, https://mojolicious.org.

AUTHOR

Roger Crew <wrog@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2020 by Roger Crew.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)