I started something yesterday that is only a syntactic sugar for
web.DB, the doctest:

>>> db = DB(db='foo.db')
>>> foo = db.table('foo')
>>> foo.select(_test=True)
<sql: 'SELECT * FROM foo'>
>>> foo.select(where='id = 3', limit=5, _test=True)
<sql: 'SELECT * FROM foo WHERE id = 3 LIMIT 5'>

And also started to try doing easier "joins".

>>> foo = db.table('foo', joins={'bar':{'from':'bar_id','to':('bars','id')}})
>>> foo.select(joins=['bar'], _test=True)
<sql: 'SELECT * FROM foo, bars WHERE foo.bar_id = bars.id'>
>>> foo.select(where='foo.id = 3', limit=5, joins=['bar'], _test=True)
<sql: 'SELECT * FROM foo, bars WHERE foo.bar_id = bars.id AND foo.id =
3 LIMIT 5'>

That information:

{'from':'bar_id','to':('bars','id')}

can also be read from the table itself, i.e. in SQLite.

>>> import web
>>> db = web.database(dbn="sqlite", db="foo.db")
>>> db.query('PRAGMA foreign_key_list(foo)').list();
[<Storage {'table': u'bar', 'from': u'bar_id', 'id': 0, 'seq': 0, 'to': u'id'}>]

which is convenient for lazy people ;-)

I'm still not convinced by the too verbose syntax and still have to
think about rewritting or not the where and fields (as the fields can
also be guessed) with a (i.e.) PRAGMA request. It's doable to rewrite
a "id = 3" into "foo.id = 3" knowing the fields of both table (and
using the principal one first).

It's a maybe overkill, waaaay overkill. But still interesting to think
about. As I'm a little bit lost on what matters and what don't, any
feedbacks/ideas you may have will help me.

Cheers,

-- Yoan

On Thu, Apr 17, 2008 at 6:28 AM, MilesTogoe <[EMAIL PROTECTED]> wrote:
>
>  Yoan Blanc wrote:
>  > About "conversions", don't you think a module would be more
>  > appropriate/pythonic?
>  >
>  My original idea was to have these methods in the model class - but  I
>  think you are right - any generic conversions like these should be in a
>  module.
>
>
>  > 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.
>  >
>  good idea.  In PHP I developed a generic model class and then had
>  individual table classes which inherited the base model class - the
>  classes handled basic CRUD.  I think this same idea would be good in
>  webpy - adds a good "model" structure without all the overhead of an
>  ORM.  This would be a good "webpy cookbook" addition.
>
>  in many ways, webpy reminds me of the PHP framework "CodeIgniter" which
>  has a separate model module but does not rely on it (and I never used it).
>
>
>
>
>
>  >
>

--~--~---------~--~----~------------~-------~--~----~
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