diff --git a/dejavu/database.py b/dejavu/database.py index b0bfc4a..5903541 100755 --- a/dejavu/database.py +++ b/dejavu/database.py @@ -164,3 +164,7 @@ def get_database(database_type=None): return db_cls raise TypeError("Unsupported database type supplied.") + + +# Import our default database handler +import dejavu.database_sql diff --git a/dejavu/database_sql.py b/dejavu/database_sql.py index 03c8ad6..a93b1f9 100644 --- a/dejavu/database_sql.py +++ b/dejavu/database_sql.py @@ -1,5 +1,5 @@ from __future__ import absolute_import -from itertools import izip_longest +from itertools import izip_longest, ifilter import Queue import MySQLdb as mysql @@ -302,10 +302,17 @@ class SQLDatabase(Database): # (sid, db_offset - song_sampled_offset) yield (sid, offset - mapper[hash]) + def __getstate__(self): + return (self._options,) + + def __setstate__(self, state): + self._options, = state + self.cursor = cursor_factory(**self._options) + def grouper(iterable, n, fillvalue=None): args = [iter(iterable)] * n - return izip_longest(fillvalue=fillvalue, *args) + return (ifilter(None, values) for values in izip_longest(fillvalue=fillvalue, *args)) def cursor_factory(**factory_options):