Shorter is possible and means writing directly the
db.select/insert/update methods which makes sense and is right imho.
So, please, drop the code I've written. The use case where db.py
become a bit tricky to use is with join and so on and it also the
place where ORMs starts not doing their job the way they should (i.e.
piggybacking). I think you can create more complex function that can
build the joins for you but its also interesting to estimate how
big/complex it would be without it.

I'm pretty confident that all those ORMs are very good, reinventing
SQL is a bit naughty though. The strength of ORMs is to offer an
abstraction layer to SQL. How leaky is it and do you need to learn a
new way of querying data?

-- Yoan

On Wed, Apr 16, 2008 at 9:48 AM, Yoan Blanc <[EMAIL PROTECTED]> wrote:
> I don't see the link between the ORM and allowing new methods/objects
>  within the templates ?
>
>  How web.py blocks you from using any ORM out there (SQLObject, Storm,
>  SQLAlchemy, ...)?
>
>  About "conversions", don't you think a module would be more
>  appropriate/pythonic?
>
>  "Static methods don't receive the instance as the first argument. They
>  can be be thought of as functions living in the namespace of the
>  class. They are similar to the same concept in Java or C++. They are
>  not very useful in Python (just use a normal function instead) but can
>  be used for helper functions in a class, which doesn't need access to
>  self, and are no use outside the class." --
>  http://chrisarndt.de/talks/rupy/2008/output/slides.html
>
>  People are arguing that ORMs are only leaky abstraction, and trying to
>  build the perfect one will result at reinventing SQL itself. Which is
>  not false imho. You can easily build generic methods to fetch object.
>
>  $ sqlite3 temp.db
>  sqlite> CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT,
>  email TEXT, firstname TEXT, lastname TEXT);
>
>  >>> import web
>  >>> from web.db import sqlwhere
>  >>> db = web.database(dbn="sqlite", db="temp.db")
>  >>> def get(table, offset=None, limit=100, **kwargs):
>  ...     return db.select(table, where=sqlwhere(kwargs), offset=offset,
>  limit=limit)
>  ...
>  >>> def post(table, **kwargs):
>  ...     return db.insert(table, **kwargs)
>  ...
>  >>> def update(table, where=None, **kwargs):
>  ...     assert where is not dict
>  ...     return db.update(table, where=sqlwhere(where), **kwargs)
>  ...
>
>  a Storify object is a dict, so once you have on, you can give it to
>  any of those functions.
>
>  >>> yoan = {"email": "[EMAIL PROTECTED]", "firstname": "Yohan"}
>  >>> post("users", **yoan)
>  1
>  >>> yoan2 = get("users", email="[EMAIL PROTECTED]")
>  >>> yoan2 = get("users", email="[EMAIL PROTECTED]").list()[0]
>  >>> yoan2
>  <Storage {'lastname': None, 'id': 1, 'firstname': u'Yohan', 'email':
>  u'[EMAIL PROTECTED]'}>
>  >>> yoan2.firstname = "Yoan"
>  >>> yoan2.lastname = "Blanc"
>  >>> update("users", where={"id": yoan2.id}, **yoan2)
>  1
>  >>> get("users", email="[EMAIL PROTECTED]").list()[0]
>  <Storage {'lastname': u'Blanc', 'id': 1, 'firstname': u'Yoan',
>  'email': u'[EMAIL PROTECTED]'}>
>
>  Now, you can do a lot better/reliable, but it will be difficult to be
>  shorter. "impossible n'est pas français" (which means "impossible
>  isn't French").
>
>  Have fun!
>
>  -- Yoan
>
>
>
>  On Wed, Apr 16, 2008 at 6:26 AM, MilesTogoe <[EMAIL PROTECTED]> wrote:
>  >
>  >  Anand Chitipothu wrote:
>  >  > On Wed, Apr 16, 2008 at 7:34 AM, MilesTogoe <[EMAIL PROTECTED]> wrote:
>  >  >
>  >  >>  In webpy can I pass a class into a template like a model ?  I have a
>  >  >>  class with many coordinate conversion functions for SVG and so I don't
>  >  >>  want to pass each function into the template as a global function - is
>  >  >>  there a way to pass in entire class ?
>  >  >>
>  >  >
>  >  > Yes.
>  >  > May be you want to pass them as globals so that you don't have to pass
>  >  > that with every template call.
>  >  >
>  >  >     web.template.Template.globals['conversions'] = conversions
>  >  >
>  >  > Are you sure you want to pass the class and not the object?
>  >  >
>  >  thks.  But I think I'm going to switch to using SQLObject which gives me
>  >  the model classes where I can have these kind of functions.  I actually
>  >  think a light ORM will be a benefit to our webpy  app especially in a
>  >  complex application (we have about 50+ tables)
>  >
>  >
>  >
>  >
>  >
>  >  > >
>  >  >
>  >  >
>  >
>  >
>  >  >  >
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to