mirror of
https://github.com/ankitects/anki.git
synced 2025-12-14 07:10: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={
|
mapper(Fact, factsTable, properties={
|
||||||
'model': relation(Model),
|
'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,
|
ForeignKey, Boolean, String, Date,
|
||||||
UniqueConstraint, Index, PrimaryKeyConstraint)
|
UniqueConstraint, Index, PrimaryKeyConstraint)
|
||||||
from sqlalchemy import create_engine
|
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
|
object_session as _object_session
|
||||||
from sqlalchemy.sql import select, text, and_
|
from sqlalchemy.sql import select, text, and_
|
||||||
from sqlalchemy.exceptions import DBAPIError, OperationalError
|
from sqlalchemy.exceptions import DBAPIError, OperationalError
|
||||||
|
import sqlalchemy
|
||||||
|
|
||||||
# sqlalchemy didn't handle the move to unicodetext nicely
|
# sqlalchemy didn't handle the move to unicodetext nicely
|
||||||
try:
|
try:
|
||||||
|
|
@ -100,3 +101,8 @@ def object_session(*args):
|
||||||
return SessionHelper(s, transaction=False)
|
return SessionHelper(s, transaction=False)
|
||||||
return None
|
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})
|
connect_args={'timeout': 0})
|
||||||
session = sessionmaker(bind=engine,
|
session = sessionmaker(bind=engine,
|
||||||
autoflush=False,
|
autoflush=False,
|
||||||
transactional=False)
|
autocommit=True)
|
||||||
return (engine, session)
|
return (engine, session)
|
||||||
_attach = staticmethod(_attach)
|
_attach = staticmethod(_attach)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class UnihanController(object):
|
||||||
echo=False, strategy='threadlocal')
|
echo=False, strategy='threadlocal')
|
||||||
self.session = sessionmaker(bind=self.engine,
|
self.session = sessionmaker(bind=self.engine,
|
||||||
autoflush=False,
|
autoflush=False,
|
||||||
transactional=True)
|
autocommit=True)
|
||||||
self.type = target
|
self.type = target
|
||||||
|
|
||||||
def reading(self, text):
|
def reading(self, text):
|
||||||
|
|
|
||||||
|
|
@ -106,9 +106,10 @@ def test_factAddDelete():
|
||||||
pass
|
pass
|
||||||
assert e.data['type'] == 'fieldNotUnique'
|
assert e.data['type'] == 'fieldNotUnique'
|
||||||
# try delete the first card
|
# 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
|
# and the second should clear the fact
|
||||||
deck.deleteCard(f.cards[1].id)
|
deck.deleteCard(id2)
|
||||||
|
|
||||||
def test_cardOrder():
|
def test_cardOrder():
|
||||||
deck = DeckStorage.Deck()
|
deck = DeckStorage.Deck()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue