Re: [CDBI] question about set_sql and iterators
Bill Moseley <[email protected]> Thu, 19 Nov 2009 06:09:34 -0800
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
--===============1298150384== Content-Type: multipart/alternative; boundary=000e0cd211d4d3a5a40478b9e9c9 --000e0cd211d4d3a5a40478b9e9c9 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Nov 19, 2009 at 4:45 AM, <arnim.rupp-5Wlsihp/[email protected]> wrote: > > I don't think you've really understood how object-relational mappers > > work. > > i would say it's more a question if there can be just one database-table > in one class. as soon as I use set_sql to select from 2+ tables that's > not the case anyway. > Yes, one class is one "table", but there's lots of options. You could define a view in your database and then create a class for the view just like any other table. Probably won't be able to update w/o more database help. You can create very complex queries with set_sql, and use TEMP columns as pointed out. IIRC, you don't even need TEMP column if you pass the object to something like Template Toolkit (which I hope you are) because it can treat it like a hash. That should drive OO purest nuts. If you don't care about relationships and just want to display the result you can use set_sql and then get an $sth with $object->sql_<name used in se_sql> and then use standard DBI and return whatever data structure you want. I do that all the time for complex pages that need to be optimized for speed. If you need all the relationships you can use the above to fetch $sth and normal DBI and then construct your objects however you wish (Yes, I've done this). Finally, there's Class::DBI::Sweet where you can specify prefetch similar to DBIx::Class that wlll do the joins for your and build the objects. This is useful if your custom SQL is really there just for the join. Class::DBI::Sweet adds a lot of useful features somewhat similar to DBIx::Class but with CDBI you still have lazy column loading and things like $cd->artist->id won't trigger a separate database query. -- Bill Moseley [email protected] --000e0cd211d4d3a5a40478b9e9c9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On Thu, Nov 19, 2009 at 4:45 AM, <span = dir=3D"ltr"><<a href=3D"mailto:arnim.rupp-5Wlsihp/[email protected]">arnim.rupp@lhsy= stems.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style= =3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; p= adding-left: 1ex;"> <div class=3D"im">> I don't think you've really understood how o= bject-relational mappers<br> > work.<br> <br> </div>i would say it's more a question if there can be just one databas= e-table<br> in one class. as soon as I use set_sql to select from 2+ tables that's<= br> not the case anyway.<br></blockquote><div><br>Yes, one class is one "t= able", but there's lots of options.<br><br>You could define a view= in your database and then create a class for the view just like any other = table.=A0 Probably won't be able to update w/o more database help.<br> <br>You can create very complex queries with set_sql, and use TEMP columns = as pointed out.=A0 IIRC, you don't even need TEMP column if you pass th= e object to something like Template Toolkit (which I hope you are) because = it can treat it like a hash.=A0 That should drive OO purest nuts.<br> <br>If you don't care about relationships and just want to display the = result you can use set_sql and then get an $sth with $object->sql_<na= me used in se_sql> and then use standard DBI and return whatever data st= ructure you want.=A0 I do that all the time for complex pages that need to = be optimized for speed.<br> <br>If you need all the relationships you can use the above to fetch $sth a= nd normal DBI and then construct your objects however you wish (Yes, I'= ve done this).<br><br>Finally, there's Class::DBI::Sweet where you can = specify prefetch similar to DBIx::Class that wlll do the joins for your and= build the objects.=A0 This is useful if your custom SQL is really there ju= st for the join.=A0 Class::DBI::Sweet adds a lot of useful features somewha= t similar to DBIx::Class but with CDBI you still have lazy column loading a= nd things like $cd->artist->id won't trigger a separate database = query.<br> <br><br></div></div><br>-- <br>Bill Moseley<br><a href=3D"mailto:moseley@ha= nk.org">[email protected]</a><br> --000e0cd211d4d3a5a40478b9e9c9-- --===============1298150384== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ClassDBI mailing list ClassDBI-Ra3b/[email protected] http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi --===============1298150384==--