DBIx::Class::Allocator - DBIx::Class component for allocating blocks of auto-incremented columns
In your DBIC ResultSet package for a particular model:
__PACKAGE__->load_components(qw/
Allocator
/);
__PACKAGE__->allocated_column('table_id'); # Assuming there is an autoincrement
# column named 'table_id'
Then, with your ResultSet instance:
my ($first_id, $last_id) = $resultset->allocate_ids(10); # Allocates 10 ids
A DBIx::Class component that gives ResultSets the ability to allocate blocks of auto-increment ids from the database. This is useful for creating id pools that an application can reserve and use without having to be connected (through a web interface) to the database (e.g. mobile apps that might not always have network connectivity).
The following RDBMS systems are currently supported: - PostgreSQL - SQLite
For SQLite, the call to allocated_column
is unnecessary. SQLite stores the autoincrement sequences on a table level (in the sqlite_sequence
table), so the column it is used with is irrelevant.
None by default.
Ben Keith, <[email protected]>
Copyright (C) 2012 by Ben Keith
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.