March 13, 2008

Simple web2py and Elixir

Filed under: dev, elixir, orm, sqlalchemy, web2py — michaelangela @ 6:56 am

So I have a sample data set in a database created by web2py. After some experimentation I can access, modify and create data with Elixir/SQLAlchemy. Just some notes, like remember to encode web2py blobs with utf8 if you’re not going through web2py’s functions.

r[0].instructions=u’some text to submit’.encode(‘utf8’)

And then something happend before this got pulished and it broke. Shame. Oh well…


March 10, 2008

Elixir or straight SQLAlchemy

Filed under: dev, elixir, orm, python, sqlalchemy — michaelangela @ 1:40 pm

Or “When not to use something that looks like it’s obviously going to make your life so much easier” 🙂

SQLAlchemy, Declarative layers, and the ORM ‘Problem’

On first glance, its pretty obvious that everyone should love Elixir vs the obviously more tedious SA approach of layout out your tables, then mapping them to the class objects. However, look at these two examples, and try to quickly answer the following questions:

  • How do you add a column to the many to many table to store an additional bit of info for the join?
  • Do they both enforce referential integrity?
  • How do you control whether SA is eager loading the relation? Can you restrict it to just one column of the relation?
  • What are the table names used?
  • How many tables are in your database?
  • Where do you change the id column name?
  • Which one is closer to the Zen of Python?

Create a free website or blog at WordPress.com.