I've been looking through the MiddleKit doc a bit, thinking about ways to
leverage it for some new parts of my application. My app is ported from a
python ASP implementation, and I had been using the SQLDict module to
provide object-database bindings. This has worked pretty well and allows
no-code-change transition from SQL Server, Oracle and MS Access databases
depending on the deployment configuration.

just for some brief background, code to fetch a record and set some
fieldswith SQLDict might look like

>>> # ... setup code omitted
>>># get a record based on name
>>>person = db.Users.findByName['Chris'].fetchone()
>>>print person.State
KY
>>> person.State = 'MA'
>>> person.Street = 'Main St.'
>>> db.Users.findByName['Chris'] = person
>>> db.commit()

There are a couple of nice features. One is that record access looks very
much like dictionary access (you can create indicies that use multiple keys
too). The other is that field access is just like attribute access in
python.

The functionality covers basic needs so far, but I was looking at MiddleKit
becuase:
   + Being able to generate SQL code to create a schema is useful (that kind
of thing is maintained by hand now)
   + method based field access allows range checking or other validation for
setting values (as well as manipulation on fetch)
   + SQLDict doesn't handle table relations(you have to roll your own
wrapper based on the straight table classes)

The last item might be the biggest motivator, though having a tool to help
maintain the schema would save some effort too. Having been spoiled by the
SQLDict way of doing things, however, the idea of trading

    print person.name
    person.state = 'MA'
    person.street = 'Main St'

for the getter/setter style:

    print person.name()
    person.setState('MA')
    person.setStreet('Main St')

doesn't sit well with me. Maybe it's just a stylistic thing, but doing
getters/setters all over the place reminds me of the java and C++ code that
python let me (almost completely) leave behind. In the past, allowing access
like this has been possible in python, but not always efficient (or pretty)
because of the __getattr__ trickiness. Python 2.2 gives us properties though
so what I'd really like to see the MiddleKit generator do is create code
along the lines of
class MyObj(object):
    def __init__(self):
         _attribute = None
    def setAttribute(self, value):
        .... validate, set, etc
    def getAttribute(self, value):
        .... return val, do other stuff, etc
    attribute = property (getAttribute, setAttribute)

There's really only a couple of differences from the current code gen:
        + getters are getName() instead of Name()
        + addition of property
        + class has to be derived from object (for now anyway, I think it'll be
automatic in some later Python version 3.0?)


Of course, this only works in 2.2, but seems like you could control the code
gen behavior in the Settings.config file that the generator uses.

Are there any plans for this kind of modification to the generator?
(responses such as "feel free to make a patch" are fine, I just didn't know
if someone had done this already, or if there was any interest in general)

Chris

p.s.  I'm sure you can now picture me posting a message like:
        from servlets, I'd really like to be able to say
                self.request.fields
        instead of
                self.request().fields()

but don't get me started.... :)


_______________________________________________________________

Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to