denisenkom/pytds — pull request #27 by VFLashM (2014-04-30 17:14:18+00:00)
Title: Flexible row type configuration

Other python db api implementations often support named rows (usually using namedtuples).
Accessing row values by names instead of indices makes code much more readable. It also makes it more maintainable, because indices may slide when query changes, but names will stay the same.

This change adds support for customizable row types. Connection can be configured to return:
* lists (mutable indexed rows)
* tuples (immutable indexed rows)
* dicts
* namedtuples (immutable named rows)
* recordtypes (mutable named rows, needs recordtype module)
* custom user-defined rows

To do so following changes were made:
1. Row creation moved to dbapi module. tds session always returns list, dbapi then wraps it with correct row type. This keeps row creation functionality localized in dbapi module.
2. Connection now has _row_strategy field. It basically a function that takes list of column names and return factory that creates row. For example, for namedtuple it receives list of column names and returns correct namedtuple type that is next used to create rows.
3. Cursor now has _row_factory field. It's basically result of _row_strategy call, i.e. a function (or any other callable including types) that creates a row out of it's arguments. In most cases it's just a row type.
3. Added as_dict property/argument backward compatibility layer