Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Why did DBIC overtake CDBI?

by mreece (Friar)
on Sep 12, 2006 at 21:26 UTC ( [id://572628]=note: print w/replies, xml ) Need Help??


in reply to Re: Why did DBIC overtake CDBI?
in thread Why did DBIC overtake CDBI?

one thing about CDBI's lack of joins is that classes can have relationships mapped to other classes that live in other databases. do you know how DBIC handles this (i.e., transparently?)?

(aside: one thing that bugs me about the various ORM solutions is that they want to handle their own db connections and want me to provide DSNs instead of $dbhs. with CDBI this is relatively easy to get around by overriding My::CDBI->db_Main(). is it that easy with RDBO or DBIC?)

Replies are listed 'Best First'.
Re^3: Why did DBIC overtake CDBI?
by siracusa (Friar) on Sep 13, 2006 at 02:50 UTC
    aside: one thing that bugs me about the various ORM solutions is that they want to handle their own db connections and want me to provide DSNs instead of $dbhs. with CDBI this is relatively easy to get around by overriding My::CDBI->db_Main(). is it that easy with RDBO or DBIC?

    In Rose::DB::Object, the database connection is abstracted by a separate class (Rose::DB). Each RDBO object "has a" Rose::DB object, and each Rose::DB "has a" plain old DBI $dbh. If you want to get your $dbh from elsewhere and use it with RDBO, all you need to do is override init_db() in your common RDBO base class to get your $dbh, shove it into a Rose::DB object, and return it.

    The database connection is "object data" in the world of RDBO and can be passed in (or swapped out) just like any other piece of data, on a per-object basis if needed. You can even load an object from one database and save it into another by swapping db objects between load() and save() operations.

    (Thanks to some semi-heroic column type abstraction, you can even do this if the database software is different in the two databases (e.g., load from MySQL and save into Postgres). There's an example of this in the tutorial.)

      i'm commenting a bit late, so maybe i won't get an answer, but how does one "shove [an existing $dbh] into a Rose::DB object"?

      i've been reading the docs and tutorial for Rose::DB but don't see how to stuff a $dbh into it, only how to get one out.

Re^3: Why did DBIC overtake CDBI?
by perrin (Chancellor) on Sep 12, 2006 at 22:10 UTC
    Rose is flexible about how connections are provided. I'm not sure if there's an easy way to use it to fake joins across databases though. That would be a good question for the mailing list.

    I can't answer your DBIC questions because I haven't used it. I'd suggest posting a top-level question or asking on the mailing list.

      I'm not sure if there's an easy way to use it to fake joins across databases though.

      If by "database" you mean "database server instance" (i.e., a different $dbh) then no, RDBO can't join across that when fetching multiple objects.

      When dealing with a single object, however, it's possible to pull related objects from other databases. e.g.

      $p = Product->new(id => 123)->load; # row from products table in db #1 $v = $p->vendor; # related row from vendors table in db #2

      But all the multi-object "all at once" fetching is done using SQL JOINs, which don't work against separate database server instances.

      Now if by "database" you mean something like a MySQL database (e.g., foodb.sometable and bardb.othertable) or a Postgres schema (e.g., public.table1 and alternate.table2), then yes, RDBO should be able to JOIN across those because they are addressable in a single SQL query run on a single $dbh.

Re^3: Why did DBIC overtake CDBI?
by jasonk (Parson) on Sep 19, 2006 at 22:22 UTC
    (aside: one thing that bugs me about the various ORM solutions is that they want to handle their own db connections and want me to provide DSNs instead of $dbhs. with CDBI this is relatively easy to get around by overriding My::CDBI->db_Main(). is it that easy with RDBO or DBIC?)

    With L<DBIx::Class::Schema> you can do this quite simply:

    package MySchema; #... setup schema stuff here ... __PACKAGE__->connection(sub { # Do whatever you want to do to build your $dbh return $dbh; });

    We're not surrounded, we're in a target-rich environment!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://572628]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-29 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found