Move dict_factory out of database class.

This commit is contained in:
Tim 2015-12-06 18:09:18 +02:00
parent a5bd7e6563
commit 37b92f3d88

View file

@ -46,6 +46,13 @@ def get_cache_size():
return 0 return 0
return int(plexpy.CONFIG.CACHE_SIZEMB) return int(plexpy.CONFIG.CACHE_SIZEMB)
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
class MonitorDatabase(object): class MonitorDatabase(object):
@ -58,14 +65,7 @@ class MonitorDatabase(object):
self.connection.execute("PRAGMA journal_mode = %s" % plexpy.CONFIG.JOURNAL_MODE) self.connection.execute("PRAGMA journal_mode = %s" % plexpy.CONFIG.JOURNAL_MODE)
# 64mb of cache memory, probably need to make it user configurable # 64mb of cache memory, probably need to make it user configurable
self.connection.execute("PRAGMA cache_size=-%s" % (get_cache_size() * 1024)) self.connection.execute("PRAGMA cache_size=-%s" % (get_cache_size() * 1024))
self.connection.row_factory = self.dict_factory self.connection.row_factory = dict_factory
def dict_factory(self, cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
def action(self, query, args=None, return_last_id=False): def action(self, query, args=None, return_last_id=False):
if query is None: if query is None: