Sequences


Role::Pg::Sequences is a Moose role for accessing and manipulating sequences in PostgreSQL.
While using my development time to build a new order/invoicing system in Djet, I develop some modules for specific issues that I bump into.

The latest one is Role::Pg::Sequences, which is a Moose role for accessing and manipulating sequences in PostgreSQL.

The Issue

If you've ever written an invoicing system, you know that you need consecutive numbers. Orders, and invoices need to be uniquely identifiable for both sender and receiver. Now, there is a great number of ways to provide numbers, but for this purpose I'd like to use the sequences in PostgreSQL.

A PostgreSQL sequence is a special kind of database object designed for generating unique numeric identifiers. It is typically used to generate artificial primary keys, but you can use it for anything you like, including just making sure that you'll get the next number.

Sequences are not standard SQL, so you have to do all the work yourself, so instead of inventing the sequences wheel every time I need it, I wrote this module.

Methods include create_sequence, drop_sequence, the boolean method sequence_exists, nextval, setval,and lastval. I think the names are pretty self explanatory.

As an example, if you'd like to get the next order number, do something like this:

=head2 get_order_number

Get (and optionally create first) the order number

=cut

sub get_order_number {
    my $self = shift;
    $self->sequences_schema('global');
    my $sequence_name = 'ordernumber';
    $self->create_sequence(sequence => $sequence_name) unless $self->sequence_exists(sequence => $sequence_name);
    return $self->nextval(sequence => $sequence_name);
}

Role::Pg::Sequences is a tiny module, focusing on doing only one thing, accessing the Sequences of the PostgreSQL database. If you have that need, perhaps this module is for you.

ARRFddVXcoUi

7DPsPi itvucxvjigcv, [url=http://vgrkftihjznn.com/]vgrkftihjznn[/url], [link=http://kivwuukqwgpq.com/]kivwuukqwgpq[/link], http://nbryljdmblqh.com/

kEfdWkzHUZe

UOKyeV http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com

Comments

Fields in bold are mandatory
Name
Email Address
Subject
Comment