mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
apsw -> nullpool
This commit is contained in:
parent
d02c1fb70a
commit
2e2444f488
1 changed files with 13 additions and 17 deletions
24
anki/deck.py
24
anki/deck.py
|
@ -2664,7 +2664,7 @@ backupDir = os.path.expanduser("~/.anki/backups")
|
|||
|
||||
class DeckStorage(object):
|
||||
|
||||
def Deck(path=None, backup=True, lock=True, apsw=False):
|
||||
def Deck(path=None, backup=True, lock=True, progress=False):
|
||||
"Create a new deck or attach to an existing one."
|
||||
create = True
|
||||
if path is None:
|
||||
|
@ -2677,7 +2677,7 @@ class DeckStorage(object):
|
|||
# sqlite needs utf8
|
||||
sqlpath = path.encode("utf-8")
|
||||
try:
|
||||
(engine, session) = DeckStorage._attach(sqlpath, create, apsw)
|
||||
(engine, session) = DeckStorage._attach(sqlpath, create, progress)
|
||||
s = session()
|
||||
metadata.create_all(engine)
|
||||
if create:
|
||||
|
@ -2715,7 +2715,7 @@ class DeckStorage(object):
|
|||
deck.needLock = lock
|
||||
deck.progressHandlerCalled = 0
|
||||
deck.progressHandlerEnabled = False
|
||||
if not apsw:
|
||||
if progress:
|
||||
try:
|
||||
deck.engine.raw_connection().set_progress_handler(
|
||||
deck.progressHandler, 100)
|
||||
|
@ -2792,23 +2792,19 @@ class DeckStorage(object):
|
|||
return deck
|
||||
Deck = staticmethod(Deck)
|
||||
|
||||
def _attach(path, create, apsw=False):
|
||||
def _attach(path, create, progress=False):
|
||||
"Attach to a file, initializing DB"
|
||||
if apsw:
|
||||
import apsw
|
||||
acon = apsw.Connection(unicode(path, "utf-8"))
|
||||
def connect():
|
||||
pycon = sqlite.connect(acon, isolation_level=None)
|
||||
return pycon
|
||||
engine = create_engine('sqlite:///', creator=connect)
|
||||
else:
|
||||
if path is None:
|
||||
path = "sqlite://"
|
||||
else:
|
||||
path = "sqlite:///" + path
|
||||
if progress:
|
||||
engine = create_engine(path,
|
||||
strategy='threadlocal',
|
||||
connect_args={'timeout': 2})
|
||||
connect_args={'timeout': 0})
|
||||
else:
|
||||
engine = create_engine(path,
|
||||
poolclass=NullPool,
|
||||
connect_args={'timeout': 30})
|
||||
session = sessionmaker(bind=engine,
|
||||
autoflush=False,
|
||||
autocommit=True)
|
||||
|
|
Loading…
Reference in a new issue