[Dbix-class] Re: using as normal perl module

Rajeev Prasad rp.neuli at yahoo.com
Fri Jul 29 22:07:28 GMT 2011


Hello Adam,

thank you.I am totally new to DB access using perl. I have looked at perl D=
BI and DBIx::Class. I can get up to speed on DBI comparatively easily i gue=
ss. (But), i want to start and stick to DBIx::Class, as i want to eventuall=
y use Catalyst. Catalyst prefers DBIx::Class, so wanted to start from it.

when i saw CPAN for both I understood DBI methods easily and clearly compar=
ed to DBIx.
use DBI; $dbh =3D DBI->connect($dsn, $user, $password, { RaiseError =3D> 1,=
 AutoCommit =3D> 0 });

where as in comparison i do not see (even in your example below) anything s=
imilar in DBIx case. (like) =A0 =A0 use DBIx::Class; ... etc.

hence the confusion.

I am so new with using perl with DBI, I have no code yet written (sorry).

Hence I was looking for something simple. which fetches data from tables, u=
ses it and then stores some data into tables. as cgi script.


thank you.
Rajeev



________________________________
From: Adam Sj=F8gren <asjo at koldfront.dk>
To: dbix-class at lists.scsys.co.uk
Sent: Friday, July 29, 2011 3:41 PM
Subject: [Dbix-class] Re: using as normal perl module

On Thu, 28 Jul 2011 14:52:35 -0700 (PDT), Rajeev wrote:

> all the examples i see are of using the module in a webapp (built with
> catalyst). I am only trying to use it in my cgi perl programe, but
> finding very less documentation. can someone please refer a URL or
> small script which stores and retrieves data from a table using this
> module plz.

I recently used DBIx::Class in a very simple command-line script that
reads files from the filesystem and stuffs them into the database.

I looked roughly like this:

=A0 #!/usr/bin/perl

=A0 use strict;
=A0 use warnings;
=A0 use utf8;
=A0 use File::Slurp qw(slurp);

=A0 use MessageID::DB;

=A0 my $schema=3DMessageID::DB->connect('dbi:Pg:dbname=3Dmessage-id', 'USER=
', 'PASSWD', { AutoCommit=3D>1, pg_enable_utf8=3D>1 });

=A0 my $transaction=3Dsub {
=A0 =A0 =A0 while(my $filename=3D<>) {
=A0 =A0 =A0 =A0 =A0 chomp $filename;
=A0 =A0 =A0 =A0 =A0 my $article=3Dslurp($filename);
=A0 =A0 =A0 =A0 =A0 my $message_id=3Dextract_message_id($article, $filename=
);
=A0 =A0 =A0 =A0 =A0 $schema->resultset('Article')->create({ message_id=3D>$=
message_id, article=3D>$article });
=A0 =A0 =A0 }
=A0 };

=A0 $schema->txn_do($transaction);

It is trivial, but you asked for something that doesn't use Catalyst and
is small (I left out the helper-sub and the error-checking) :-)

Maybe if you show what you have tried and describe what you wanted, it
is easier to get help.


=A0 Best regards,

=A0 =A0 Adam

-- =

"Good car to drive after a war"=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 Adam Sj=F8gren
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 asjo at koldfront.dk

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co=
.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20110729/d81=
97028/attachment.htm


More information about the DBIx-Class mailing list