[Dbix-class] Re: using as normal perl module
will trillich
will.trillich at serensoft.com
Fri Jul 29 22:18:22 GMT 2011
Dave posted a good link with a straightforward example for DBIx::Class, have
you checked this out?
http://search.cpan.org/~abraxxa/DBIx-Class-0.08195/lib/DBIx/Class/Manual/Ex=
ample.<http://search.cpan.org/~abraxxa/DBIx-Class-0.08195/lib/DBIx/Class/Ma=
nual/Example.pod>
pod<http://search.cpan.org/~abraxxa/DBIx-Class-0.08195/lib/DBIx/Class/Manua=
l/Example.pod>
It's really pretty sweet.
One of the nice things about the Catalyst setup is that you don't have to do
the schema part by hand, as the example shows:
http://search.cpan.org/~abraxxa/DBIx-Class-0.08195/lib/DBIx/Class/Manual/Ex=
ample.pod#Set_up_DBIx::Class::Schema
Instead, Catalyst gives your app its own XXX_create.pl script to handle that
for you, once you have your tables and fields set up.
On Fri, Jul 29, 2011 at 10:07 PM, Rajeev Prasad <rp.neuli at yahoo.com> wrote:
> Hello Adam,
>
> thank you. I am totally new to DB access using perl. I have looked at perl
> DBI and DBIx::Class. I can get up to speed on DBI comparatively easily i
> guess. (But), i want to start and stick to DBIx::Class, as i want to
> eventually 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
> compared 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
> similar in DBIx case. (like) 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,
> uses 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:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use utf8;
> use File::Slurp qw(slurp);
>
> use MessageID::DB;
>
> my $schema=3DMessageID::DB->connect('dbi:Pg:dbname=3Dmessage-id', 'USER=
',
> 'PASSWD', { AutoCommit=3D>1, pg_enable_utf8=3D>1 });
>
> my $transaction=3Dsub {
> while(my $filename=3D<>) {
> chomp $filename;
> my $article=3Dslurp($filename);
> my $message_id=3Dextract_message_id($article, $filename);
> $schema->resultset('Article')->create({ message_id=3D>$message_=
id,
> article=3D>$article });
> }
> };
>
> $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.
>
>
> Best regards,
>
> Adam
>
> --
> "Good car to drive after a war" Adam Sj=F8gr=
en
> 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
>
>
>
> _______________________________________________
> 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
>
-- =
"Don't just accept the benefits of civilization -- add to it. Extend it.
Preserve it." -- Jeff Greason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20110729/e23=
7a373/attachment-0001.htm
More information about the DBIx-Class
mailing list