#25 Adds by[IndexName] method for every unique index.


This is the summary of changes (copied from the patch).

User-visible Changes:
Now, fo each DatabaseIndex with unique=True you
have an extra method
by[IndexName] like by[AlternateID], that takes
as parameters the columns
used in the index. You can specify an extra
option when creating
DatabaseIndex, alternateMethodName, just like
with Columns with

Internal Changes:
Now dbconnection.DBAPI._SO_selectOneAlt() can
accept a sequence for
'column' and 'value' parameters. Both must have
the same len() and it's
mapped in the query as column[0] = value[0] AND
... column[N] = value[N]

index.SODatabaseIndex() constructor takes an
extra optional parameter
'alternateMethodName' wich is set by default to

main.sqlmeta.addIndex() now adds the proper
by[IndexName] method to
soClass, using
main.sqlmeta._SO_fetchAlternateID() to retrieve the data.

main.sqlmeta._SO_fetchAlternateID() now takes
an extra optional
parameter 'idxName' with the index name (when
it's called for an index)
for error reporting purpose. 'column' and
'value' parameters can accept
a sequence just like


  • Leandro Lucarella

  • Leandro Lucarella

    Logged In: YES

    Here's a simple example of use.

  • Oleg Broytman

    Oleg Broytman - 2005-10-31
    • assigned_to: nobody --> phd
    • status: open --> open-invalid
  • Ian Bicking

    Ian Bicking - 2005-10-31

    Logged In: YES

    (copied from email comments)

    I don't want anymore automatic addition of methods to
    SQLObject classes -- I'm not very happy with the ones that
    already exist.

    Instead, I'd like index objects to become smarter, since
    they are already being explicitly named and put on the class
    as attributes. Potentially these objects could be callable,
    or have a .get() method. So it would be like:

    class Contact(SQLObject):

    areaCode = StringCol()
    number = StringCol()
    phoneIndex = DatabaseIndex('areaCode', 'number',

    Contact.phoneIndex.get('555', '555-5555')
    # Also allowable:
    Contact.phoneIndex.get(number='555-5555', areaCode='555')

  • Oleg Broytman

    Oleg Broytman - 2005-11-02

    Logged In: YES

    Applied at the revision 1192 to the trunk. Thank you!

  • Oleg Broytman

    Oleg Broytman - 2005-11-02
    • status: open-invalid --> closed-accepted

Log in to post a comment.