Table Of Contents

Porting Guide from SQLObject to Elixir over SQLAlchemy

Migrate Model

  1. import elixir instead of import sqlobject

from:

from turbogears.database import PackageHub
from sqlobject import *

to:

from elixir import *
  1. subclass Entity insteasd of SQLObject

from:

class List(SQLObject):
    pass

to:

class List(Entity):
    pass
  1. use Field(Type()) instead of TypeCol()

from:

class List(SQLObject):
    title = UnicodeCol(notNone=True)

to (Elixir 0.4):

class List(Entity):
    title = Field(Unicode, nullable=False)

or to (Elixir 0.3):

class List(Entity):
    has_field('title', Unicode, nullable=False)
  1. MultipleJoin/ForeignKey ->has_many/belongs_to

from:

class List(SQLObject):
    items = MultipleJoin('Item')

class Item(SQLObject):
    list = ForeignKey('List')

to (Elixir 0.4):

class List(Entity):
    OneToMany('Items')

class Item(Entity):
    ManyToOne('List')

or to (Elixir 0.3):

class List(Entity):
    has_many('items', of_kind='Item')

class Item(Entity):
    belongs_to('list', of_kind='List')

Check http://elixir.ematia.de/trac/wiki/TutorialDivingIn to become familiar with the usage of elixir.

Migrate Query

Basic get

Basic get method is the same (in Elixir 0.3 and 0.4):

record = User.get(id)

Get by name

Same, but you need to specify the argument name.

from:

records = User.getByName("Fred")

to:

records = User.get_by(name = "Fred")

Basic select

Use ‘c’ in sqlalchemy instead of ‘q’ in sqlobject.

from:

records = User.select(User.q.user_name == "Fred")

to (Elixir 0.4):

records = User.query.filter(User.c.user_name == "Fred").all()

or to (Elixir 0.3):

records = User.select(User.c.user_name == "Fred")

Select by name

selectByName method -> select_Name method

from:

records = User.selectByName("Fred")

to (Elixir 0.4):

records = User.query.filter_by(name = "Fred").all()

or to (Elixir 0.3):

records = User.select_by(name = "Fred")