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.)
| [reply] [Watch: Dir/Any] |
| [reply] [Watch: Dir/Any] [d/l] [select] |
$db->dbh( $dbh );
| [reply] [Watch: Dir/Any] [d/l] |
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. | [reply] [Watch: Dir/Any] |
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. | [reply] [Watch: Dir/Any] [d/l] |
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! |
---|
| [reply] [Watch: Dir/Any] [d/l] |