An Introduction to Class::DBI - Introduction 8

One Table, One Class

  • Create a single class to encapsulate a single database table:

        CREATE TABLE nomination (
            id              INTEGER PRIMARY KEY,
            type            VARCHAR(255),
            year            INTEGER,
            film_id         INTEGER,
            credit_id       INTEGER,
            takes_the_oscar INTEGER
        package Nomination;
        use base 'Class::DBI';
        Nomination->set_db('Main', 'dbi:pg', 'dbi_user', 'dbi_password');
        Nomination->columns('id','type', 'year', 'film_id', 'credit_id', 'takes_the_oscar');
        Nomination->columns(Primary => 'id');


YAPC::Canada << Previous | Index | Next >>
Copyright © 2003 Michael Graham