Message234424
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. |
|
Date |
User |
Action |
Args |
2015-01-21 04:43:50 | YoSTEALTH | set | recipients:
+ YoSTEALTH, rhettinger, ghaering, ncoghlan, eric.araujo, BreamoreBoy, petri.lehtinen, serhiy.storchaka, dlenski, Russell.Sim |
2015-01-21 04:43:50 | YoSTEALTH | set | messageid: <1421815430.01.0.727518493422.issue13299@psf.upfronthosting.co.za> |
2015-01-21 04:43:49 | YoSTEALTH | link | issue13299 messages |
2015-01-21 04:43:49 | YoSTEALTH | create | |
|