Hi.
On 31/10/2010, Xiao Lan (小兰) <[email protected]> wrote:
> Hello,
>
> For me I have been using DBI for all kinds of database handling.
OK.
> But some applications require an ORM for database, like what the
> DBIx::Class module does.
Righty. If I understand what you want you're saying, then all you have
to make sure is you use DBIx::Class in your code and also provide
existing database schema like so-
use lib '/some/exported/db/schema' # use `dbicdump` for this if you
have existing database
use MyDB::Schema;
,,,,
> Under what case shall we use the ORM instead of DBI with original SQL input?
I use an ORM (DBIx::Class for Perl) so I can wrap SQL statements
nicely without having to write one manually. There's provision in
DBIx::Class to write SQL statements if you would want that as well.
Also, you are essentially not having to use database driver specific
code (it handles them somewhat transparently / automagically for you -
PG / MySQL / SQLite for e.g.)
If you go through DBIx::Class documentation[1], it pretty much tells
you everything you need to know and is documented excellently. If you
have existing DB, you can export the Schema nicely into a set of class
mappings using `dbicdump` and use the Schema as if it were your usual
class.
A simple example would be something along these lines:
use Foo::Schema;
....
$rs->search({
id = $id, # WHERE id = $id
});
return $rs->next;
[...]
More @ http://search.cpan.org/dist/DBIx-Class/
Enjoy!
--
Regards
Ishwor Gurung
Key id:0xa98db35e
Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/