-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed as not planned
Labels
Description
The row factory example that returns a namedtuple in the sqlite docs creates a new namedtuple class for every row instance and as a result is really, really slow. A couple of orders of magnitude slower is too much even for an example, people might still use it and assume that one class per row doesn't affect performance that much. Introducing caching makes the example a bit less concise, but at least it becomes usable.
from collections import namedtuple
from functools import lru_cache
@lru_cache
def make_row_class(description):
return namedtuple('Row', (col[0] for col in description))
def named_tuple_factory(cursor, row):
return make_row_class(cursor.description)(*row)
Metadata
Metadata
Assignees
Labels
Projects
Status
Done