Author YoSTEALTH
Recipients BreamoreBoy, Russell.Sim, YoSTEALTH, dlenski, eric.araujo, ghaering, ncoghlan, petri.lehtinen, rhettinger, serhiy.storchaka
Date 2015-01-21.04:43:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1421815430.01.0.727518493422.issue13299@psf.upfronthosting.co.za>
In-reply-to
Content
note: sqlite_namedtuplerow.patch _cache method conflicts with attached database with say common table.column name like "id"

Using namedtuple method over sqlite3.Row was a terrible idea for me. I thought namedtuple is like tuple so should be faster then dict! wrong. I wasted 2 days change my work to namedtuple and back to sqlite3.Row, the speed difference on my working project was:

namedtuple 0.035s/result
sqlite3.Rows 0.0019s/result

for(speed test) range: 10000
namedtuple 17.3s
sqlite3.Rows 0.4s

My solution was to use sqlite3.Row (for speed) but to get named like usage by convert dict keys() with setattr names:

class dict2named(dict):
    def __init__(self, *args, **kwargs):
        super(dict2named, self).__init__(*args, **kwargs)
        self.__dict__ = self

Usage:

for i in con.execute('SELECT * FROM table'):
    yield dict2named(i)

Now i can use:

print(i.title)

and handy dict methods for dash column names:

print(i['my-title'])
print(i.get('my-title', 'boo'))

Now working project speed:
sqlite3.Rows 0.0020s/result

for(speed test) range: 10000
sqlite3.Rows 0.8s with dict2named converting

This i can work with, tiny compromise in speed with better usage.
History
Date User Action Args
2015-01-21 04:43:50YoSTEALTHsetrecipients: + YoSTEALTH, rhettinger, ghaering, ncoghlan, eric.araujo, BreamoreBoy, petri.lehtinen, serhiy.storchaka, dlenski, Russell.Sim
2015-01-21 04:43:50YoSTEALTHsetmessageid: <1421815430.01.0.727518493422.issue13299@psf.upfronthosting.co.za>
2015-01-21 04:43:49YoSTEALTHlinkissue13299 messages
2015-01-21 04:43:49YoSTEALTHcreate