[Dbix-class] Re: Primary key using a Sequence Generator

Dagfinn Ilmari Mannsåker ilmari at ilmari.org
Fri Feb 8 22:08:54 GMT 2008


Steve Kirkup <skirkup at jupiterimages.com> writes:

> Hello,
>
>
> Is there a clean way to override the insert() method to call a sequence
> generator for getting a primary key?
>
> I would assume it is possible, but I am unsure where it would go.

The way to do this is to have your database supply the value (via a
trigger or default value or similar) and tell DBIC by adding
is_auto_inrement => 1 to the column info hash in add_columns. It will
then take care of fetching the auto-generated PK for newly inserted
rows.

If you are using DBIx::Class::Schema::Loader to create your schema
classes, try out the latest development version¹, which supports this
for MySQL, PostgreSQL and SQLite. I've just committed Oracle support to
SVN², it will be included in 0.04999_02. DB2 is still missing, but I'd
like to have that before releasing 0.05.

[1]: <http://search.cpan.org/~ilmari/DBIx-Class-Schema-Loader-0.04999_01/>
[2]: <http://dev.catalyst.perl.org/repos/bast/branches/DBIx-Class-Schema-Loader/current>

-- 
ilmari
"A disappointingly low fraction of the human race is,
 at any given time, on fire." - Stig Sandbeck Mathisen




More information about the DBIx-Class mailing list