mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
add option to initialize via apsw
This commit is contained in:
parent
1b1b69e966
commit
090529c4d7
1 changed files with 17 additions and 9 deletions
26
anki/deck.py
26
anki/deck.py
|
@ -2664,7 +2664,7 @@ backupDir = os.path.expanduser("~/.anki/backups")
|
||||||
|
|
||||||
class DeckStorage(object):
|
class DeckStorage(object):
|
||||||
|
|
||||||
def Deck(path=None, backup=True, lock=True):
|
def Deck(path=None, backup=True, lock=True, apsw=False):
|
||||||
"Create a new deck or attach to an existing one."
|
"Create a new deck or attach to an existing one."
|
||||||
create = True
|
create = True
|
||||||
if path is None:
|
if path is None:
|
||||||
|
@ -2677,7 +2677,7 @@ class DeckStorage(object):
|
||||||
# sqlite needs utf8
|
# sqlite needs utf8
|
||||||
sqlpath = path.encode("utf-8")
|
sqlpath = path.encode("utf-8")
|
||||||
try:
|
try:
|
||||||
(engine, session) = DeckStorage._attach(sqlpath, create)
|
(engine, session) = DeckStorage._attach(sqlpath, create, apsw)
|
||||||
s = session()
|
s = session()
|
||||||
metadata.create_all(engine)
|
metadata.create_all(engine)
|
||||||
if create:
|
if create:
|
||||||
|
@ -2791,15 +2791,23 @@ class DeckStorage(object):
|
||||||
return deck
|
return deck
|
||||||
Deck = staticmethod(Deck)
|
Deck = staticmethod(Deck)
|
||||||
|
|
||||||
def _attach(path, create):
|
def _attach(path, create, apsw=False):
|
||||||
"Attach to a file, initializing DB"
|
"Attach to a file, initializing DB"
|
||||||
if path is None:
|
if apsw:
|
||||||
path = "sqlite://"
|
import apsw
|
||||||
|
acon = apsw.Connection(path)
|
||||||
|
def connect():
|
||||||
|
pycon = sqlite.connect(acon)
|
||||||
|
return pycon
|
||||||
|
engine = create_engine('sqlite:///', creator=connect)
|
||||||
else:
|
else:
|
||||||
path = "sqlite:///" + path
|
if path is None:
|
||||||
engine = create_engine(path,
|
path = "sqlite://"
|
||||||
strategy='threadlocal',
|
else:
|
||||||
connect_args={'timeout': 0})
|
path = "sqlite:///" + path
|
||||||
|
engine = create_engine(path,
|
||||||
|
strategy='threadlocal',
|
||||||
|
connect_args={'timeout': 2})
|
||||||
session = sessionmaker(bind=engine,
|
session = sessionmaker(bind=engine,
|
||||||
autoflush=False,
|
autoflush=False,
|
||||||
autocommit=True)
|
autocommit=True)
|
||||||
|
|
Loading…
Reference in a new issue