Python and Jongo

For some reason or another, I've always found Python support for RDBMS lacking behind Java, specially in the ORM area. Just imagine, there are no officially supported Python drivers to connect to an Oracle database and you must install the Oracle client... ugh!

Anyway, by having a Jongo server connected to your database you don't have to worry about installing any Python modules, you'll only need a standard Python 2.4+ installation with simplejson or Python 2.5+ which already support JSON.

Let's see, for example, an application which accesses the CIDB database and the Car table:

import jongo

class Car(jongo.JongoModel):
    def __init__(self, id=None, model=None, maker=None, fuel=None, transmission=None, year=None):
        jongo.JongoModel.__init__(self) = id
        self.idCol = "cid"
        self.model = model
        self.maker = maker
        self.fuel = fuel
        self.transmission = transmission
        self.year = year

class CarStore(jongo.JongoStore):
    def __init__(self):
        self.model = Car
        self.proxy = jongo.Proxy("localhost:8080","cidb","car", Car)

if __name__ == '__main__':
    carstore = CarStore()
    for car in
        print car

    c1 = Car(None, "206cc", "Peugeot", "Gasoline", "Manual", 2008)

    c1 = carstore.getAt(carstore.count() - 1)
    c1.set('model', "206")
    c1.set('maker', "PPegoushn")

    # We need to refresh the object since it has changed after the sync
    c1 = carstore.getAt(carstore.count() - 1)

Since this is Python, the code is pretty straightforward and self documented, right? For more information and examples on working with Python and Jongo check this page.