Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flask_session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def _get_interface(self, app):
config.setdefault('SESSION_MONGODB_COLLECT', 'sessions')
config.setdefault('SESSION_SQLALCHEMY', None)
config.setdefault('SESSION_SQLALCHEMY_TABLE', 'sessions')
config.setdefault('SESSION_SQLALCHEMY_SEQUENCE', None)

if config['SESSION_TYPE'] == 'redis':
session_interface = RedisSessionInterface(
Expand All @@ -102,7 +103,7 @@ def _get_interface(self, app):
app, config['SESSION_SQLALCHEMY'],
config['SESSION_SQLALCHEMY_TABLE'],
config['SESSION_KEY_PREFIX'], config['SESSION_USE_SIGNER'],
config['SESSION_PERMANENT'])
config['SESSION_PERMANENT'], config['SESSION_SQLALCHEMY_SEQUENCE'])
else:
session_interface = NullSessionInterface()

Expand Down
11 changes: 9 additions & 2 deletions flask_session/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,19 +466,26 @@ class SqlAlchemySessionInterface(SessionInterface):
session_class = SqlAlchemySession

def __init__(self, app, db, table, key_prefix, use_signer=False,
permanent=True):
permanent=True, sequence=None):
if db is None:
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy(app)
self.db = db
self.key_prefix = key_prefix
self.use_signer = use_signer
self.permanent = permanent
self.sequence = sequence

class Session(self.db.Model):
__tablename__ = table

id = self.db.Column(self.db.Integer, primary_key=True)
if sequence:
id = self.db.Column(self.db.Integer,
self.db.Sequence(sequence),
primary_key=True)
else:
id = self.db.Column(self.db.Integer, primary_key=True)

session_id = self.db.Column(self.db.String(255), unique=True)
data = self.db.Column(self.db.LargeBinary)
expiry = self.db.Column(self.db.DateTime)
Expand Down