Skip to content

Commit

Permalink
Support db_file_name when creating queue
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-wangxu committed May 16, 2019
1 parent 8c843d9 commit d2fbe2d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions persistqueue/sqlbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import persistqueue.serializers.pickle


sqlite3.enable_callback_tracebacks(True)

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -52,7 +51,7 @@ class SQLiteBase(object):

def __init__(self, path, name='default', multithreading=False,
timeout=10.0, auto_commit=True,
serializer=persistqueue.serializers.pickle):
serializer=persistqueue.serializers.pickle, db_file_name=None):
"""Initiate a queue in sqlite3 or memory.
:param path: path for storing DB file.
Expand All @@ -73,6 +72,8 @@ def __init__(self, path, name='default', multithreading=False,
must deserialize and return one value from fp,
and may be called multiple times with the same fp
to read multiple values.
:param db_file_name: set the db file name of the queue data, otherwise default
to `data.db`
"""
self.memory_sql = False
self.path = path
Expand All @@ -81,6 +82,9 @@ def __init__(self, path, name='default', multithreading=False,
self.multithreading = multithreading
self.auto_commit = auto_commit
self._serializer = serializer
self.db_file_name = "data.db"
if db_file_name:
self.db_file_name = db_file_name
self._init()

def _init(self):
Expand Down Expand Up @@ -118,7 +122,7 @@ def _new_db_connection(self, path, multithreading, timeout):
conn = sqlite3.connect(path,
check_same_thread=not multithreading)
else:
conn = sqlite3.connect('{}/data.db'.format(path),
conn = sqlite3.connect('{}/{}'.format(path, self.db_file_name),
timeout=timeout,
check_same_thread=not multithreading)
conn.execute('PRAGMA journal_mode=WAL;')
Expand Down

0 comments on commit d2fbe2d

Please sign in to comment.