=head1 NAME DBIx::Class::Manual::Intro - Introduction to DBIx::Class =head1 INTRODUCTION So, you are bored with SQL, and want a native Perl interface for your database? Or you've been doing this for a while with L, and think there's a better way? You've come to the right place. Let's look at how you can set and use your first native L tree. First we'll see how you can set up your classes yourself. If you want them to be auto-discovered, just skip to the next section, which shows you how to use L. =head2 Setting it up manually First, you'll need a base class. It should inherit from L like this: package MyApp::DB; use base qw/DBIx::Class/; You will also want to load some of the L components. L provides a good starter set. In addition you'll have to use either L or L. We'll use C in this introduction, since it involves less magic. C is mostly useful if you want to use multiple database connections. __PACKAGE__->load_components(qw/Core DB/); If you want serial/auto-incrementing primary keys, you should use the L component for your database. For example, if you're using SQLite add C to the list: __PACKAGE__->load_components(qw/PK::Auto::SQLite Core DB/); C classes exist for many databases; see L for more information. Once you've loaded the components, it's time to set up your connection: __PACKAGE__->connection('dbi:SQLite:/home/me/myapp/my.db'); This method is similar to the normal L C method, and can take username, password, and L attribute hash as well as the DSN. With that out of the way, we can define our first table class: package MyApp::DB::Album; use base qw/MyApp::DB/; Then we specify which table it uses, __PACKAGE__->table('album'); and specify which columns it has. __PACKAGE__->add_columns(qw/albumid artist title label year/); This will automatically create accessors for each of the columns, so that you can read/update the values in rows you've retrieved. Also, you need to tell it which column is the primary key: __PACKAGE__->set_primary_key('albumid'); If you have a primary key composed of multiple columns, just pass a list instead. That's pretty much all you need for a basic setup. If you have more advanced needs like using more than one database connection for the same class, see L. =head2 Using L This is an additional class, and not part of the L distribution. Like L, it inspects your database, and automatically creates classes for all the tables in your database. Here's a simple setup: package MyApp::DB; use DBIx::Class::Loader; my $loader = DBIx::Class::Loader->new( dsn => 'dbi:SQLite:/home/me/myapp/my.db', namespace => 'MyApp::DB' ); 1; This should be equivalent to the manual setup in the section above. L takes lots of other options. For more information, consult its documentation. =head2 Basic usage Once you've defined the basic classes, either manually or using L, you can start interacting with your database. The simplest way to get a record is by primary key: my $album = MyApp::DB::Album->find(14); This will run a C