diff --git a/minode/sql.py b/minode/sql.py index 00bdd0d..33fd2ee 100644 --- a/minode/sql.py +++ b/minode/sql.py @@ -41,14 +41,16 @@ class Inventory(): cur.execute("INSERT INTO status VALUES ('lastvacuumtime', ?)", (now,)) self._db.commit() + @staticmethod + def __object(cursor, row): + vector, expires, obj_type, version, stream, tag, data, offset = row + return structure.Object( + expires, obj_type, version, stream, data, offset, + tag=tag, vector=vector) + def __objects(self, cur): - return ( - structure.Object( - expires, obj_type, version, stream, data, offset, - tag=tag, vector=vector) - for (vector, expires, obj_type, version, stream, tag, data, offset) - in cur.fetchall() - ) + cur.row_factory = self.__object + return cur def cleanup(self): with shared.objects_lock: @@ -80,7 +82,7 @@ class Inventory(): ' ORDER BY random()', (int(time.time()), stream or shared.stream) ) - return [v for v, in cur.fetchall()] + return [v for v, in cur] def get(self, vector, default=None): try: @@ -90,7 +92,7 @@ class Inventory(): def keys(self): cur = self._db.execute('SELECT vector FROM objects') - return (v for v, in cur.fetchall()) + return (v for v, in cur) def values(self): cur = self._db.execute('SELECT * FROM objects') @@ -114,14 +116,11 @@ class Inventory(): def __getitem__(self, vector): cur = self._db.execute( 'SELECT * FROM objects WHERE vector = ?', (vector,)) + cur.row_factory = self.__object item = cur.fetchone() if item is None: raise KeyError(vector) - vector, expires, obj_type, version, stream, tag, data, offset = item - return structure.Object( - expires, obj_type, version, stream, data, offset, - tag=tag, vector=vector - ) + return item def __delitem__(self, vector): with shared.objects_lock: # KeyError