mirror of
https://github.com/ankitects/anki.git
synced 2025-12-13 14:50:59 -05:00
sqlalchemy 0.5 compat
This commit is contained in:
parent
2b30578615
commit
7c764763d2
5 changed files with 13 additions and 6 deletions
|
|
@ -265,7 +265,7 @@ mapper(Card, cardsTable, properties={
|
|||
|
||||
mapper(Fact, factsTable, properties={
|
||||
'model': relation(Model),
|
||||
'fields': relation(Field, backref="fact", order_by=Field.c.ordinal),
|
||||
'fields': relation(Field, backref="fact", order_by=Field.ordinal),
|
||||
})
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,10 +28,11 @@ from sqlalchemy import (Table, Integer, Float, Column, MetaData,
|
|||
ForeignKey, Boolean, String, Date,
|
||||
UniqueConstraint, Index, PrimaryKeyConstraint)
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import mapper, sessionmaker, relation, backref, \
|
||||
from sqlalchemy.orm import mapper, sessionmaker as _sessionmaker, relation, backref, \
|
||||
object_session as _object_session
|
||||
from sqlalchemy.sql import select, text, and_
|
||||
from sqlalchemy.exceptions import DBAPIError, OperationalError
|
||||
import sqlalchemy
|
||||
|
||||
# sqlalchemy didn't handle the move to unicodetext nicely
|
||||
try:
|
||||
|
|
@ -100,3 +101,8 @@ def object_session(*args):
|
|||
return SessionHelper(s, transaction=False)
|
||||
return None
|
||||
|
||||
def sessionmaker(*args, **kwargs):
|
||||
if sqlalchemy.__version__ < "0.5":
|
||||
kwargs['transactional'] = not kwargs['autocommit']
|
||||
del kwargs['autocommit']
|
||||
return _sessionmaker(*args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -1909,7 +1909,7 @@ alter table cardModels add column typeAnswer boolean not null default 0""")
|
|||
connect_args={'timeout': 0})
|
||||
session = sessionmaker(bind=engine,
|
||||
autoflush=False,
|
||||
transactional=False)
|
||||
autocommit=True)
|
||||
return (engine, session)
|
||||
_attach = staticmethod(_attach)
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class UnihanController(object):
|
|||
echo=False, strategy='threadlocal')
|
||||
self.session = sessionmaker(bind=self.engine,
|
||||
autoflush=False,
|
||||
transactional=True)
|
||||
autocommit=True)
|
||||
self.type = target
|
||||
|
||||
def reading(self, text):
|
||||
|
|
|
|||
|
|
@ -106,9 +106,10 @@ def test_factAddDelete():
|
|||
pass
|
||||
assert e.data['type'] == 'fieldNotUnique'
|
||||
# try delete the first card
|
||||
deck.deleteCard(f.cards[0].id)
|
||||
id1 = f.cards[0].id; id2 = f.cards[1].id
|
||||
deck.deleteCard(id1)
|
||||
# and the second should clear the fact
|
||||
deck.deleteCard(f.cards[1].id)
|
||||
deck.deleteCard(id2)
|
||||
|
||||
def test_cardOrder():
|
||||
deck = DeckStorage.Deck()
|
||||
|
|
|
|||
Loading…
Reference in a new issue