[SQLObject] [PATCH] Specifying indexes
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Jeremy F. <je...@go...> - 2004-07-23 08:12:33
|
My app relies on SQLObject to create its tables initially. This has the problem that there's no way to specify indexes for each table. This patch (against SVN head) implements an Index() class which allows you to add indexes. Its use is pretty simple: from sqlobject import * class Foo(SQLObject): foo = IntCol() bar = StringCol() biff = IntCol() idx1 = Index(foo) # simple index idx2 = Index(bar, unique=True) # simple unique index idx3 = Index((biff, foo)) # multi-column index idx4 = Index(((biff, 4),)) # only the first 4 chars of biff are used There are no operations which can be applied to Indexes; they're used implicitly (one assumes) during queries. The only time Index() has an actual effect is during createTable. I've only implemented support in the databases I have on hand: SQLite and MySQL. Adding createIndexSQL for the other database types should be easy. This is also the first time I've dug about SQLObject's innards, so I'm not really sure if I've done things right. The mapping from a Col to SOCol via the name seems a bit tortured. Does this look like an acceptable way of dealing with this problem? J |